How to invoke SOAP web service with C#
Locked
-
Monday, December 11, 2006 11:29 PMNew to programming and need help on invoking a SOAP webservice in C#. I'm not getting a response from my Web Request code below. Is the WebRequest/WebReponse object suitable for invoking SOAP webservices? Please let me know what modifications I need to make. Any help is appreciated.
public DataSet GetMeter(string DEVICEID, string UID)
{
//create a web request object
WebRequest request = WebRequest.Create(ConfigurationSettings.AppSettings["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><serviceRequestTimeStamp>" + 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
Answers
-
Tuesday, December 12, 2006 12:17 AMModerator
If you are just starting, you should use the Windows Communication Foundation instead of ASP.NET Web Services. We've done all the work that you are just trying to do here. :-)
Creating a client: http://msdn2.microsoft.com/en-us/library/ms733133.aspx
WCF landing page: http://msdn2.microsoft.com/en-us/library/ms735119.aspx
-
Tuesday, December 12, 2006 1:04 AM
Clemens Vasters - MSFT wrote: If you are just starting, you should use the Windows Communication Foundation instead of ASP.NET Web Services. We've done all the work that you are just trying to do here. :-)
Creating a client: http://msdn2.microsoft.com/en-us/library/ms733133.aspx
WCF landing page: http://msdn2.microsoft.com/en-us/library/ms735119.aspx
Thanks for providing the links. I posted here because I need an answer soon. I have been looking around various parts of the site and the web but didn't have luck finding instructions. Also I need someone to verify my code to see if I'm heading towards the right direction. -
Tuesday, December 12, 2006 1:14 AMModerator
Well, that was the answer. What you are trying to do here is not heading in the right direction, because you are trying to do something by foot for which two frameworks already exist: WCF and ASP.NET Web Services. If you are using Visual Studio, you have the "Add Web Reference" feature of ASP.NET Web Services readily available in each project and that's going to do all the work for you that you are trying to replicate here. I am, however, suggesting, that you take a look at WCF as well.
All Replies
-
Tuesday, December 12, 2006 12:17 AMModerator
If you are just starting, you should use the Windows Communication Foundation instead of ASP.NET Web Services. We've done all the work that you are just trying to do here. :-)
Creating a client: http://msdn2.microsoft.com/en-us/library/ms733133.aspx
WCF landing page: http://msdn2.microsoft.com/en-us/library/ms735119.aspx
-
Tuesday, December 12, 2006 1:04 AM
Clemens Vasters - MSFT wrote: If you are just starting, you should use the Windows Communication Foundation instead of ASP.NET Web Services. We've done all the work that you are just trying to do here. :-)
Creating a client: http://msdn2.microsoft.com/en-us/library/ms733133.aspx
WCF landing page: http://msdn2.microsoft.com/en-us/library/ms735119.aspx
Thanks for providing the links. I posted here because I need an answer soon. I have been looking around various parts of the site and the web but didn't have luck finding instructions. Also I need someone to verify my code to see if I'm heading towards the right direction. -
Tuesday, December 12, 2006 1:14 AMModerator
Well, that was the answer. What you are trying to do here is not heading in the right direction, because you are trying to do something by foot for which two frameworks already exist: WCF and ASP.NET Web Services. If you are using Visual Studio, you have the "Add Web Reference" feature of ASP.NET Web Services readily available in each project and that's going to do all the work for you that you are trying to replicate here. I am, however, suggesting, that you take a look at WCF as well. -
Thursday, December 28, 2006 9:36 PMCould any one let me know how can you call WCF Webservice with out proxy class from WCF client???
-
Friday, December 29, 2006 3:01 PM
Hi,
You can try with this project,
http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=ProxyFactory
It automatically generates a dynamic proxy for an specific WSDL on the fly,
so you can invoke the web service without having the .NET generated proxy.
Regards,
Pablo Cibraro. -
Thursday, April 30, 2009 7:17 PMWell this can be done in a more simple way as to make it more understandeable...check out this link...Vinu - Genie
-
Friday, May 01, 2009 11:36 AMModeratorVinu, thanks for the help, but this is the second time I've seen you answer a two year old question that was already marked as answered.
John Saunders
Use File->New Project to create Web Service Projects
Use WCF for All New Web Service Development, instead of old ASMX or obsolete WSE -
Sunday, November 07, 2010 12:33 AMJohn - but sometimes the answers are ____ and then get outdated. It is 2010 and this is still a relevant question as there is NOTHING still 4 years later that is good regarding SOAP and C#.

