Monday, July 13, 2009

How to pass data object from .Net to Java Webservice

This is a simple guide that you should know about how to pass data object from .Net application to java web service.In this case we use Axis2 webservice angine to run those java web services.Important thing that you want know is that List obect cann't be passed between .Net and java webservice.If you want pass the List then you have to make array from list.array obect is allowed to pass.

This is simple webservice written by java.

public UserData getUserData(UserData userData){

return userData;

In above method Userdata is Data object that can be hold all user information.

You can reffer for how to know implementing .aar file for axis2.
  • After Implement the application we deploy the webservice in axis2 webservice engine and take the specific URL for that webservice.It shouldbe a url that is relavent wsdl file of the webservice
Eg: http://localhost:8080/axis2/services/TCSService?wsdl

I will explain step by step that how to implement dot application for our above task.

  • Create the new Project and new class on that project
  • Let see that we are going to access the following java web service method througth .Net application
  • In dotnet application our namespace is clientForUserData
  • Then Right click on the project and add the web references to that object
  • Use the above URL and search the available web services.
  • Then It list the all webservices that is found
  • Give web service name and add the webservice to your dot net project.
Eg: We give testwebservice as webservice name.
and if our webservice is TCSService (That web service method has been declared)

Bellow is sample code to access that webservice

clientForUserData.testwebservice.TCSService tcs = new clientForUserData.TCSService.TCSService();

clientForUserData.TCSService.UserData ud = new clientForUserData.TCSService.UserData(); = 'dhanushka';
ud.age = 26;

clientForUserData.TCSService.UserData updatedUD = new clientForUserData.TCSService.UserData();

updatedUD = tcs.getUserData(ud);

Console.WriteLine( );
Console.WriteLine(updatedUD.age );

Out put will be