Since .NET 3.5 you can’t add a web reference to a class library project, so how can you access web services?
Actually it is much easier.
- Right click the Class Library project and select Add Service Reference…
- Add the URL of the Web Service and click Go
- Give it a meaningful Namespace then click OK
Visual Studio will add a Service References folder and a system.serviceModel to the app.config file.
To invoke methods of the web service, first you create an instance of the SoapClient class then just use that object:
MyService.WebService1SoapClient myClient = new MyService.WebService1SoapClient();
In my example above MyService is the Namespace I used in the Add Service Reference dialog.
That is all there is to it.
I really liked this post. Can I copy it to my site? Thank you in advance.
Yes – feel free.
Richard.