Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to consume one web service and want to pass XML as input parameter into web method but it's giving me error when trying to pass xml as input parameter.

It only understand my input value when I covert input value by "HtmlEncoding" and change "<" to "& lt;" and ">" to "& gt;".

I don't want to do like this and directly pass xml node as input parameter value in web method.

Please reply me back ASAP, It's very urgent.

C#
string SOAPRequest="",SOAPInput="";

XmlDocument doc = new XmlDocument();
SOAPRequest = "<?xml version='1.0' encoding='utf-8'?>";
SOAPRequest += "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope'>";
SOAPRequest += "<soap:Body>";
SOAPRequest += "<GetCustomerInfoXML xmlns='http://qa2.alliancetek.com/phpwebservice'>";
SOAPRequest += "<id><customer><id>1</id></customer></id></GetCustomerInfoXML></soap:Body>";
SOAPRequest += "</soap:Envelope>";

doc.InnerXml = @""+SOAPRequest;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://qa2.alliancetek.com/phpwebservice/index.php");
if (proxy != null) 
{
    req.Proxy = new WebProxy(proxy, true);
}
req.Headers.Add("SOAPAction", "http://qa2.alliancetek.com/phpwebservice/index.php/GetCustomerInfoXML");
req.ContentType = "text/xml;charset=\"utf-8\"";
req.Accept = "text/xml";
req.Method = "POST";
//req.ContentLength = 1000;

Stream stm = req.GetRequestStream();
doc.Save(stm);
stm.Close();

//Stream stm;
WebResponse resp = req.GetResponse();
stm = resp.GetResponseStream();
StreamReader r = new StreamReader(stm);
//Response.Write(r.ReadToEnd());
string sResponse = r.ReadToEnd();
Posted
Updated 16-Jun-10 0:05am
v4

1 solution

Your parameters have to be escaped.

Instead of having the pointy brackets, you have to use "&lt;" and "&gt;" in your string.
 
Share this answer
 
Comments
hitesh mehta 16-Jun-10 6:21am    
Hey John,

Thanks for reply, right now I am doing on that way by encoding "<" but I want to find another way for doing this. so can u tell me how I can directly passing xml node as input without parsing or encoding it??
#realJSOP 16-Jun-10 17:32pm    
There is no other way that I know of.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900