Until now, I have been creating service references for ASMX web services in order to call them, but in this scenario, I can no longer do that. This is my first go at passing XML to service references manually.
What I am not too sure of is the level of complexity required to get a JSON string into basically an XML string to be passed to the webservice.
string func_name = "//some asmx web service function" string json_string = "//some json encoded string here"; XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(variables, "root"); StringWriter stringWriter = new StringWriter(); XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter); doc.WriteTo(xmlTextWriter); string xml_parameters = stringWriter.ToString(); //remove <root> and </root> from the string xml_parameters = xml_parameters.Replace("<root>", null).Replace("</root>", null); string request_xml= "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + "<soap:Body>" + "<" + func_name + " xmlns=\"http://tempurl.org\" >" + xml_parameters+ "</" + func_name +" >" + "</soap:Body>" + "</soap:Envelope>"; HttpResponseMessage response = client.PostAsync(uri, new StringContent(xml, Encoding.UTF8, request_header_type)).Result;
An awful lot of objects have been instantiated here in order to get my JSON converted into XML to be passed to the web service. Can anyone suggest any improvements or potential problems?