Consume a Web Service within a .NET Application Using a Proxy Assembly

This short post will give the steps to consume a web service within a .NET application.  I’m working on a project that pulls data from a web service and writes the data to a text file.  The method I used was to create a proxy assembly that I could reference within the project.  To create this proxy assembly, do the following:

  1. Create a project in Visual Studio 2008.  (I used a console app for this.)
  2. Open the Visual Studio Command Line tool.  Change the directory to the directory the new project is held in.
  3. There are two things that you need to do to create the assembly.  First, you must create a class that represents the service and the methods within the service.  Second, you must compile the class into the assembly (dll).  To create the class, first get the URL to the wsdl of the service.  Then, type the following into the command line tool:  wsdl {the url to the wsdl}.  Example – wsdl http://myservice.data.com/service?wsdl.  To create the assembly, type the following:  csc /t:library {name of the class}.cs (assuming you’re using C#).  Example – csc /t:library MyServiceClass.cs.
  4. After the command line steps, you should have the assembly in the directory of your project.  Next, go back to Visual Studio and add a reference to the dll you just created.
  5. Now, you may use the methods that are contained in the web service. 

Creating a proxy assembly is an easy way to reference a web service and use the methods within it. 

Follow

Get every new post delivered to your Inbox.