Im required to listen requests from a web service in C# and respond to them ion C# .. whats the approach to this ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I am presuming you already have a web service you wish to consume. There are several examples on consuming web services on the web (e.g.: Consuming web services from a WinForms app).
Adding a web reference
First, you need to add a web reference to your C# project. In VS2005, you can do this by right-clicking the project and selecting “Add web reference”, and the providing the url of the web service. In VS2008 or newer, there are a couple of extra clicks as described here.
After you’ve done that, VS will generate all the necessary proxy classes for you, with methods for both synchronous and asynchronous invocation, which you can use as if the object was instantiated locally.
Viewing generated classes
For example, if your web service has a single method (
DoSomething), and is located atwww.example.com/MyService.asmx(and also named “MyService”), Visual Studio will create a class called `MyService” which will look something like this:To examine the contents of the generated namespace, double click your web reference in Solution Explorer (it should be inside a folder called “Web References”). This will open the Object browser.
Using generated classes synchronously
The simplest way to use your class is to create an instance, and invoke the method:
Using generated classes asynchronously
To use the async version, you can attach an event handler: