Java Reference
In-Depth Information
Creating a .NET Web Service Client in Visual Studio
Problem
You want to create a client in Visual Studio to invoke a Java-based web service.
Solution
In Visual Studio, you can add a web reference to your project and provide a WSDL URL, and
it will create the proxy code for you. Then you can reference the service based on the server
name.
Discussion
In this example, you'll walk through the steps associated with creating a .NET client for a
web service written in Java. Using Visual Studio 2005, you can easily add a reference to an
existing web service. First, you'll create a regular console project in C# with a Main method.
Then you'll go to Project→Add Web Reference and give it the URL of a local calculator web
service written in Java. This will generate a set of proxy classes (as wsimport would in the
solution), which are now available to invoke.
This is slightly different from how you do it in Java: the proxy is in the namespace (similar to
a Java package) of the server name that hosts the WSDL. In your case, that's localhost , so
you can access your service proxy by referencing it from that namespace. The complete class
is shown in Example 12-6 .
Example12-6.SimpleCalcClient.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
InvokeCalculator();
}
private static void InvokeCalculator()
Search WWH ::




Custom Search