Need help invoking SOAP web service in C#
New to programming and need help on invoking a SOAP webservice in C#. Basically I need a way to pass in two parameters (Device ID and User ID) in a click event that transforms into a SOAP message, sends the webrequest, an returns the XML results into a dataset.
I'm not getting a response from my Web Request code below. The code I have is calling the webservice WSDL using Http/Querystring style web request. Is the WebRequest/WebReponse object suitable for invoking SOAP webservices? I don't think my request is recognized by the SOAP WSDL as I'm getting an error message during the response.
Please let me know what modifications I need to make. Any help is appreciated. Thanks. - Henry
public DataSet GetMeter( string DEVICEID, string UID)
{
//create a web request object
WebRequest request = WebRequest.Create(ConfigurationSettings.AppSetting s["METERURL"]); //Add MeterPing URL to web.config
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
Stream aStream = request.GetRequestStream ();
StreamWriter aStreamWriter = new StreamWriter(aStream);
StringBuilder aStringBuilder = new StringBuilder();
XmlDataDocument myDoc = new XmlDataDocument();
aStringBuilder.Append("message=<MeterRequest><serv iceRequestTimeStamp>" + System.DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") + "</serviceRequestTimeStamp><deviceNumber>" + DEVICEID + "</deviceNumber><deviceType>Generic</deviceType><requestorID>CC" + UID + "</requestorID></MeterRequest>");
aStreamWriter.Write(aStringBuilder);
//Close the output stream and send the data out to the web server
aStreamWriter.Close();
//get the response object from the request.
WebResponse response = request.GetResponse(); //todo: see if request.timeout default needs to be changed
|