Skip to main content

Java and .NET Interoperability - Let's just do it

Posted by rpatel on February 12, 2007 at 10:53 AM PST

With the release of Web Services Interoperability Toolkit (WSIT), many of us have been asking one basic question - how to go about making the Java and .NET endpoints work? How to prototype this interoperability? In this blog, I am outlining the steps to do just that. I will show you how to establish the most basic interoperability between Java and .NET platforms using Web services.

Step 1 - Install the following softwares on your system

1) WSIT Milestone 2 Release (wsit.dev.java.net)

2) Glassfish v2 build 18 (https://glassfish.dev.java.net/downloads/v2-b15.html)

3) NetBeans 5.5 IDE (http://www.netbeans.info/downloads/index.php?)

4) WSIT NetBeans Module v1.41 (Flash based tutorial of downloading and installing this NetBeans module is
available at http://websvc.netbeans.org/wsit/flash/DownloadInstall-Single.htm)

5) Install .NET Framework 3.0 (http://www.microsoft.com/downloads/details.aspx?FamilyId=10CC340B-F857-
4A14-83F5-25634C3BF043&displaylang=en
) (**)

6) Install .NET SDK 3.0 (http://www.microsoft.com/downloads/details.aspx?FamilyId=C2B1E300-F358-4523-B479-F53D234CDCCF&displaylang=en) (**)
** - This demo has been tested with July CTP versions of .NET Framework 3.0 and .NET SDK 3.0. Although, logically speaking, the demo script should work to showcase interoperability between Java and the more recent versions of .NET Framework and SDK.

Step 2 - Start the NetBeans 5.5 IDE

Step 3 - Deploy Java Web service endpoint

Follow this Flash tutorial to deploy a simple Java Web service, NewWebService. You should make two changes to your Web service for the purpose of showcasing interoperability with .NET:-

1) Even though the tutorial instructs to turn Reliable Messaging on, for .NET interoperability purposes, don't turn it on for simplicity sake. We will test interop between the two platforms in this demo for just MTOM functionality.

2) The July CTP versions of .NET Framework 3.0 and .NET SDK 3.0 misbehaves and sends an invalid SOAP action string to the Java Web service endpoint. See this excellent blog entry from Arun Gupta, one of our senior engineers involved with WSIT and JAX-WS, where he talks about this issue. For now the workaround is to specify explicit SOAPAction values for operations at the service endpoint. Therefore, your NewWebService Java implementation class, NewWebService.java, should look like this:

--------
package pkg;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

@WebService()
public class NewWebService {

@WebMethod(action="operation")
public String operation(@WebParam(name = "param") String param) {
// TODO implement operation
return param;
}
}
--------

Notice that here we specify SOAP action with the help of action attribute of @WebMethod annotation applicable to the Web service method.

Step 4 - Test the Java Web service endpoint

Now test whether NewWebService has been deployed properly by typing the following URL in your browser - http://localhost:8080/WebApplication1/NewWebService?WSDL

Step 5 - Generate .NET C# client artifacts

Now that our Java Web service endpoint is up and running, let us visit the .NET world for a moment to create a very simple C# client application. First, open a command prompt window, and type the following command to create C# client artifacts needed to communicate with our Web service. Notice that svcutil uses MEX (Metadata Exchange) protocol to retrieve the Web service's information.

svcutil http://localhost:8080/WebApplication1/NewWebService?wsdl /out:NewWebServiceProxy.cs
/config:NewWebServiceProxyTest.exe.config

Step 6 - Write the C# Console application client for Java Web service

Write the following C# console application (and save it as NewWebServiceProxyTest.cs) to act as a client to our Java Web service endpoint:

--------
using System;
using System.ServiceModel;
using System.ServiceModel.Description;

class NewWebServiceProxyTest {
public static void Main(string[] args) {
sample_operationResponse response;

// Create an instance of the Web service class.
NewWebService newWebService = new NewWebServiceClient();

// Call the Web service method.
response = newWebService.operation(new operationRequest(new
operationRequestBody("Hello there")));

// Output the results to the console.
Console.WriteLine("The result returned by Web service operation is: " +
response.Body.@return + ".");
}
}
--------

Step 7 - Compile the C# console application

csc /t:exe /r:c:\windows\microsoft.net\framework\v3.0\window~1\System.ServiceModel.dll,c:\windows\microsoft.net\framew
ork\v3.0\window~1\System.Runtime.Serialization.dll *.cs

In the above command, window~1 folder refers to the "Windows Communication Foundation" folder under the .NET framework installation folder.

Step 8 - Run the console application

Run the client C# console application from the command prompt, and you should see an output as below:

c:\> NewWebServiceProxyTest.exe

The result returned by Web service operation is: Hello there.

Hopefully, this demo works for you. As I gain more knowledge about making the higher layers of the WS stack interoperate, I'd blog more on the subject later.

Related Topics >>