I am trying to post XML to a web service directly rather than using VS's "add a web reference..." functionality. There is a good reason for this. To get proper test XML I logged what was generated using the standard web reference. I used what I found in this question Capturing SOAP requests to an ASP.NET ASMX web service
The web service was just what is generated when you create a new web service in visual studio, nothing fancy.
To try and pass the XML itself, I borrowed the code from this question Client to send SOAP request and received response
Unfortunately, when I call it, I get "The remote server returned an error: (500) Internal Server Error." 100% if I call the same web method like this
WebService1 ws = new WebService1();
String output = ws.HelloWorld();
then everything works great so I know the service is working well as deployed. I would appreciate so greatly some advice as to what I am doing wrong =)
Here is my code:
var _url = "http://localhost/simulator/webservice1.asmx";
var _action = "http://localhost/simulator/webservice1.asmx?op=HelloWorld";
String soapMessage = soapMessage = @"<?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><HelloWorld xmlns='http://tempuri.org/' /></soap:Body></soap:Envelope>";
XmlDocument soapEnvelop = new XmlDocument();
soapEnvelop.LoadXml(soapMessage);
XmlDocument soapEnvelopeXml = soapEnvelop;
HttpWebRequest webRequest = CreateWebRequest(_url, _action);
InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);
// begin async call to web request.
IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);
// suspend this thread until call is complete. You might want to
// do something usefull here like update your UI.
asyncResult.AsyncWaitHandle.WaitOne();
// get the response from the completed web request.
string soapResult;
using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
{
soapResult = rd.ReadToEnd();
}