Discussions

XML & Web services: HOW do I pass objects across different Web Services ???

  1. hi,

    i am trying to call a Java Web Service hosted on Tomcat-AXIS from a .NET client. It works with simple data types mostly primitive but does not when I try passing objects.

    I now tried to pass an object for eg:

    public class ABCD
    {
      int count;
      string name;
    }

    this object is defined in the Java Web service and I use it in the .NET client after adding a WEB REFERENCE to the Java Web Service.

    some relevant sample code:


    using WebReference1;

    WebReference1.ABCD objABCD = new WebReference1.ABCD;
    objABCD.count = 1;
    objABCD.name = "abc";

    Service1 svc = new Service1();

    (WebReference1.ABCD) ret = svc.helloworld(objABCD);

    This HELLOWORLD method is supposed to return the object that I pass - Thats the objective.

    I get the following exception message:

    Unhandled Exception: System.Web.Services.Protocols.SoapException: org.xml.sax.SA
    XException: Bad types (null -> class WebReference1.ABCD)
       at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClie
    ntMessage message, WebResponse response, Stream responseStream)
       at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodN
    ame, Object[] parameters)

    ********************************

    Bottomline: How do I pass objects across different Web Services made out of different Web Service platforms.

    Please let me know at your earliest convenience - Thanks at on.

    - G
  2. You don't.

    Web Services are technology nuetral, which means "Java" objects are not valid "things" that can be passed. You have to use the supported data types to represent your "object".

    Don't assume that there is a Java program running on the other side of the Web Service.

  3. Thanx for your prompt reply.

    But I have a question here.
    Do you mean to say we cannot pass any custom object (even though, its made up of basic data types like int and string) from a Java Webservice to .NET client and vice versa?
    Put some more light into this.

    Thanks and Regards,
    GG
  4. Hi,

    I think here you need to understand the ideas of marshalling/unmarshalling Objects to in this case XML and how to define Object types in Web Services.

    The most common approach to define new types in a Web Service is to use the XML Scheme Part II specification. This allows you to define custom types based of a list of already defined types. WSDL and most SOAP services support type definitions in this way.

    Check out.

    http://www.w3.org/TR/xmlschema-2/

    The SOAP spec talks a lot about serialization of Objects into SOAP XML

    http://www.w3.org/TR/SOAP/#_Toc478383515

    In the end the ability to correctly communicate custom types between Web Services is still a headache. For instance the old Apache SOAP framework did not support defining types in schemas so you had to use "xsi:type" to define the type your XML tag refers to.

    As for how you marshall your types into XML depends on the framework you are using.

    David
  5. Hi,
      If the webservice you are invoking has the custom object (either java or .NET), you need to use the marshalling or unmarshalling support provided by the corresponding SOAP toolkit. On the java side, you would have mapped the web service to a java method call and parameters to a corresponding class. This mapping has to be provided when you are deploying the web service (using deployment descriptor). Axis beta-2 provides WSDD where you can mention
    the class to be marshalled or unmarshalled. If your class
     has data following java bean convention, you do not need towrite a customer serializer/deserializer, you can use the already availalable BeanSerializer and BeanDeserializer. There are many serializer/deserializers already provided by toolkit. But if your class data needs explicit marshalling/unmarshalling you have to provide it explicitly by writing your own customer Serializer/DeSerializer.
    In the same way, even you need to provide the similar things on .NET side. I donno about .NET much, so I really cannot say how you can do it.
    Hope it helps...
    Gopi
  6. Thanks Gopi.
    I am bit new to JAVA world. I know marshalling and unmarshalling concept.
    Can you give me some small sample code for the wsdd for custom objects?

    Thanks once again!
    GG