views:

296

answers:

3

i have an ASP.NET web service that returning a custom entity object (Staff):

[WebMethod]
public Staff GetStaffByLoginID(string loginID){}

how would i consume this in Java?

thanks!

A: 

Just use Standard WSDL as mentioned by flyswat if you are using traditional asmx web services.

other solutions if not using standard ASP.NET Web Services:

Use REST

http://www.infoq.com/articles/REST-INTEROP

http://www.codeproject.com/KB/XML/WSfromJava.aspx

Make sure the objects are serializable and as long as the you can cast it to a similar class on the Java side, you are good. Else, you might have to write some custom class mappers in Java.

CodeToGlory
This is what the WSDL is for.
FlySwat
He can use http://xstream.codehaus.org/ for xml serialization and simply build REST Services.
CodeToGlory
You do realize that a WSDL is an interface for the objects passed over the wire and that he already has a perfectly good SOAP solution on both sides of the stack?
FlySwat
@FlySwat, I never disagreed with you, I am merely proposing couple of alternatives. I was not sure if the op has WSDL available, for all we know web service could be a WCF Service(though not mentioned explicitly by the op).
CodeToGlory
I will edit my solution for you :)
CodeToGlory
The [WebMethod] Attribute is not used in WCF. Instead it uses a [ServiceContract] attribute on the class, and does not decorate the individual methods.
FlySwat
A: 

You may be able to do this by running Java on IKVM.

Matthew Flaschen
The entire point of a webmethod is so you can call it via SOAP.
FlySwat
+4  A: 

ASP.NET automatically generates a WSDL that contains the interface definitions for your web methods and the types they consume/return.

Apache Axis provides a tool called WSDL2Java that will generated the all of the code you need to consume the webservice. Simply point it to:

http://yoursite.com/YourWebService.asmx?WSDL

If you browse directly to the .ASMX file, you'll get a nice test harness that you can use to explore the various methods you can call.

Once Axis reads your WSDL, it will generate some proxy classes, one of them will be based on the interface of Staff.

However, I would not use this class as your actual business object, and instead would wrap access to the web service through a service layer. This service layer would use the proxy Staff class to populate your real business object.

This protects your consuming code from any interface changes that may happen to the web service in the future, keeping the actual area of code that would be modified as small as possible.

I do this for a living, interopping between Java and .NET on many platforms using SOAP.

EDIT: Why the is this downvoted? It's the only correct answer here.

FlySwat
Probably because you came across a little douche-y, making enemies of the other two answerers. +1 for correctness though.
Rex M
The other two answers were so wrong it hurt.
FlySwat
+1 for your answer. :)
CodeToGlory
WSDL2Java seems like a good solution as there is already a WSDL available. thanks guys!
Gnot