Click here to Skip to main content
15,899,126 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i m getting this exception ...i m sending a xml file on the server and want to get to response but i m continuously getting this error
here my code..
C++
void HttpSOAPRequest(String xmlfile, string proxy)
   {
       try
       {
           XmlDocument doc = new XmlDocument();
           doc.Load(@"C:\Inetpub\wwwroot\MCBPayments\web_pages\Setup\" + xmlfile);
           HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://195.229.231.233/ICAgentIntegTest/IcWebService.asmx?wsdl");
           if (proxy != null) req.Proxy = new WebProxy(proxy, true);
           // if SOAPAction header is required, add it here...
           req.Headers.Add("SOAPAction", "IcWebService");

           req.ContentType = "text/xml;charset=\"utf-8\"";
           req.Accept = "text/xml";
           req.Method = "POST";
           Stream stm = req.GetRequestStream();
           doc.Save(stm);
           stm.Close();
           WebResponse resp = req.GetResponse();Getting Error over here
           stm = resp.GetResponseStream();
           StreamReader r = new StreamReader(stm);
           // process SOAP return doc here. For now, we'll just send the XML out to the browser ...
           Response.Write(r.ReadToEnd());
       }
Posted

1 solution

First of all, you seem to want to call a web method in a web service, right?

If that is so, instead of using HttpWebRequest object, you should call the web method in easier way, by adding a web reference in your Visual studio project to the URL http://195.229.231.233/ICAgentIntegTest/IcWebService.asmx[^] and calling the desired web method passing the XML document as parameter.

For more on consuming a web service, see http://www.4guysfromrolla.com/articles/062602-1.aspx[^]

Now, I am assuming for some reason, you are using HttpWebRequest to consume a web service instead of the natural way, and hence, coming back to your code.

First of all, you are creating a HttpWebRequest object pointing to a URL that returns the WSDL document, not the asmx itself. See, you are using the following code:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://195.229.231.233/ICAgentIntegTest/IcWebService.asmx?wsdl");


Instead, you should use the following code, that points to the asmx URL

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://195.229.231.233/ICAgentIntegTest/IcWebService.asmx");


Second, the "SOAPAction" header value should be set to a web method that is available at the asmx URL. I didn't find any web method that has a name "IcWebService" in the provided asmx URL.

The above two reasons are good enough to make the web service invocation fail and return error. There may be other issues that you may need to care about once the above two issues are fixed (Such as, making sure the corresponding web method accepts XML document, the web method works perfect without any error etc).
 
Share this answer
 

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