Generating a C#-.NET client using Visual Studio

Back to Web Services Resources and Tutorials

To create a C# console application to access the web service, open Visual Studio:

  1. Select "New Project"
  2. Under "Visual C# Projects", select "Console Application", give it a name and a directory, then click "OK".
  3. In the "Solution Explorer" window, right-click on "References" under the solution name, then select "Add Web Reference...".
  4. In the URL window, enter the full URL of the web service, with a question mark and the text "wsdl" appended, so Visual Studio can find the WSDL file; for example, enter
    http://localhost:8080/jboss-net/services/TutorialService_Port?wsdl
    
    for the JBoss-3.2.7 version, or
    http://localhost:8080/tutorial/ping
    
    for the JBoss-4.0.3 and Sun Application Server versions. VS should display the single method exposed by the web service. Give the Web reference name a value and click "Add Reference".
  5. Switch to the "Class View" and you'll see that VS has created the request and response document class, plus a proxy to the web service itself. Open the proxy class and change the "Unqualified" annotation on the request parameter to "Qualified". Axis will not accept a SOAP envelope with null namespaces for the request attributes (don't change the response attribute, however, or .NET will not understand the response).
  6. Write code to create an instance of the web service proxy and to invoke it, then compile and run. An example application can be found at Tutorial.cs.
  7. You'll probably need to run the application from a command prompt to see the output; if you run it from within Visual Studio, the command prompt will exit immediately after the application exits. The application takes two command line arguments: the endpoint URL of the web service (see the values you used to create the Web Reference, above) and the message to pass to the ping request.
If you use the example client referenced here, you will see output similar to the following (depending on which web service you are targeting):
C#/.NET tutorial web service client:
  Ping request parameter was '.NET Ping'
  Ping response is 'This is the JBoss 3.2.7 response to request '.NET Ping''

Back to Web Services Resources and Tutorials