Generating a C#-.NET console application client

Back to Web Services Resources and Tutorials

To write an console application client outside of Visual Studio, you will first need to create a .NET proxy to the JBoss web service, then refer to it (in DLL form) from the client application. These same steps occur in Visual Studio; they are just performed in the process of creating Web References. You'll need the .NET wsdl.exe utility, to create the proxy, and then csc.exe to compile it into a DLL, and to compile the command-line test client. If you have Visual Studio installed, you will be able to find wsdl.exe under that distribution; the .NET Framework should have the C# compiler csc.exe. Both utilities are available from the Visual Studio command prompt (in Windows XP, reach this via "Start | All Programs | Microsoft Visual Studio .NET 200X | Visual Studio .NET Tools | Visual Studio .NET 200X Command Prompt)

From the top-level tutorial directory, create a directory called C#.NET. From that directory, execute the following:

wsdl.exe /l:CS /protocol:SOAP ..\wsdl\tutorial.wsdl
this will generate a file called TutorialService.cs in the same directory. Since Axis won't like the unqualified attributes on the web-service request parameters, open this file and change the "Unqualified" attribute on the PingRequestType's "requestParam" to "Qualified". Then, from the C#.NET directory, compile the proxy into a DLL with
csc.exe /t:library /r:System.Web.Services.dll /r:System.Xml.dll TutorialService.cs

For the console application, you can write one in a text editor or just use the Tutorial.cs file generated in the Visual Studio version. If you use the version generated in Visual Studio, you will need to make some modifications:

  1. You'll need to remove the "using WSClient.tutorial" directive, since the proxy you created here does not exist in a namespace.
  2. Since slightly different tools were used to generate the proxy, the "pingRequest" method from the Visual Studio version of the Web reference is actually "PingRequest" in this proxy, so change the referenced method name in the client to "PingRequest".
This version of the client can be found at Tutorial.cs.

Next, compile this from the C#.NET directory (assuming the client is in the same directory) with:

csc.exe /r:TutorialService.dll Tutorial.cs
then execute the application Tutorial.exe with the command
Tutorial endpointURL pingMessage
where the endpoint URL is either
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. You should see the following output or something similar, depending on the details of your client and 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