![]() | |
|
The process of creating a WCF C# client to a Web Service is similar to that for a Java programming language client. To create a WCF client you will:
Use the svcutil.exe tool to generate the C# proxy class and contracts for accessing the web service.
Create a client program that uses the generated files to make calls to the Web Service.
You must have the following software installed to create the WCF client:
Microsoft Windows Software Development Kit (SDK) for July Community Technology Preview
Microsoft .NET Framework 3.0 RTM
The .cs client enabled from Java
You must also deploy the Java web service.
The Client Class
The client class uses a generated proxy class, AddNumbersImpl, to access the web service. The port instance variable stores a reference to the proxy class:
... port = new AddNumbersImplClient("AddNumbersImplPort"); ...
Then the web service operation addNumbers is called on port:
... int result = port.addNumbers (number1, number2); ...
The following is the full Client.cs class:
using System; class Client { static void Main(String[] args) { AddNumbersImplClient port = null; try { port = new AddNumbersImplClient("AddNumbersImplPort"); int number1 = 10; int number2 = 20; Console.Write("Adding {0} and {1}. ", number1, number2); int result = port.addNumbers (number1, number2); Console.WriteLine("Result is {0}.\n\n",result); number1 = -10; Console.Write("Adding {0} and {1}. ", number1, number2); result = port.addNumbers (number1, number2); Console.WriteLine("Result is {0}.\n\n",result); port.Close(); } catch (System.ServiceModel.FaultException e) { Console.WriteLine("Exception: " + e.Message); if (port != null) port.Close(); } } }
When creating a Java programming language client, you use the wsimport tool to generate the proxy and helper classes used by the client class to access the web service. When creating a WCF client, the svcutil.exe tool provides the same functionality as the wsimport tool. svcutil.exe generates the C# proxy class and contracts for accessing the service from a C# client program:
svcutil /config:Client.exe.config http://localhost:8080/wsit-enabled-fromjava/addnumbers?wsdl
The command compiles the proxy class, configuration file, and Client.cs client class into the Client.exe executable file:
C:\WINNT\Microsoft.NET\Framework\v2.0.50727\csc.exe /r:"C:\WINNT\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\System.ServiceModel.dll" /r:"C:\WINNT\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\System.Runtime.Serialization.dll" Client.cs AddNumbersImplService.csYou can change the location of the csc.exe C# compiler and the System.ServiceModel and System.Runtime.Serialization support DLLs if you installed the .NET 2.0 and 3.0 frameworks to non-default locations.
![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |