I am trying use a web service in a C# ASP.Net Web Application. The service is built in PHP and is located on some remote server not under my control so I cant modify it to add
As referenced that - you will have to hand code your "proxy" for this web service.
One example of manually making a web service call - you may have to tweak the method some.
private string MakeWebServiceCall(string methodName, string requestXmlString)
{
WebRequest webRequest = WebRequest.Create("https://subreg.forpsi.com/robot2/subreg_command.php");
HttpWebRequest httpRequest = (HttpWebRequest)webRequest;
httpRequest.Method = "POST";
httpRequest.ContentType = "text/xml";
httpRequest.Headers.Add("SOAPAction: https://subreg.forpsi.com/robot2/subreg_command.php/" + methodName);
Stream requestStream = httpRequest.GetRequestStream();
//Create Stream and Complete Request
StreamWriter streamWriter = new StreamWriter(requestStream);
streamWriter.Write(String.Format(this.GetSoapString(), requestXmlString));
streamWriter.Close();
//Get the Response
WebResponse webResponse = httpRequest.GetResponse();
Stream responseStream = webResponse.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream);
//Read the response into an xml document
System.Xml.XmlDocument soapResonseXMLDocument = new System.Xml.XmlDocument();
soapResonseXMLDocument.LoadXml(streamReader.ReadToEnd());
//return only the xml representing the response details (inner request)
return soapResonseXMLDocument.GetElementsByTagName(methodName + "Result")[0].InnerXml;
}
I would recommend creating xsd's which can be used to generate objects (using xsd.exe) and then you can serialized/deserialize responses and requests to actually objects.
EDIT: GetSoapString() method
private string GetSoapString()
{
StringBuilder soapRequest = new StringBuilder("");
soapRequest.Append("{0}");
soapRequest.Append(" ");
return soapRequest.ToString();
}
For Steve's Reference
Call one looks like:
123
Response:
false