views:

154

answers:

2

Hello everyone,

I have been given by a partner a WSDL for their Web Services. I'm not too experienced with Web Services, so I'm a bit skeptical about something with the WSDL. One particular method allows us to get some information, but we can only use it once (or face a penalty.) The problem is that it is returned as "raw XML" inside the SOAP response, so I'm not exactly sure what will be returned, and thus how to deal with it and properly store it.

The relevant part of the WSDL is this:

<s:element name="MethodResponse"> 
    <s:complexType> 
      <s:sequence> 
        <s:element minOccurs="0" maxOccurs="1" name="MethodResult"> 
          <s:complexType mixed="true"> 
            <s:sequence> 
              <s:any /> 
            </s:sequence> 
          </s:complexType> 
        </s:element> 
      </s:sequence> 
    </s:complexType> 
  </s:element>

wsimport generated the following class:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "methodResult"
})
@XmlRootElement(name = "MethodResponse")
public class MethodResponse {

    @XmlElement(name = "MethodResult")
    protected MethodResponse.MethodResult methodResult;

    public MethodResponse.MethodResult getMethodResult() {
        return methodResult;
    }

    public void setMethodResult(MethodResponse.MethodResult value) {
        this.methodResult = value;
    }


    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "content"
    })
    public static class MethodResult {

        @XmlMixed
        @XmlAnyElement(lax = true)
        protected List<Object> content;

        public List<Object> getContent() {
            if (content == null) {
                content = new ArrayList<Object>();
            }
            return this.content;
        }

    }

}

So the question is, what will be the class of the objects returned by getContent()? A sample C# sample that they provided doesn't have a MethodResponse or MethodResult, but the return type is just XmlNode.

BTW, even though the code was generated by wsimport, the application uses Axis2. The other methods available return proper objects.

A simple test (sample server running on Mono) generated an exception on the client side:

Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Could not deserialize Soap message

Thanks in advance.

+3  A: 

Mixed content elements are a bit of a tricky one to handle in JAXB.

Your List<Object> can be a mix of:

  • String, to represent text content in the element
  • JAXBElement, to represent element types known to the schema which don't have the @XmlRootElement annotation
  • Instances of classes known to the context which do have @XmlRootAnnotation
  • org.w3c.dom.Element if the content is not known to the context

The javadoc for @XmlMixed goes into more detail, but that's the basis of it.

skaffman
Well, from the simple test, it looks like Axis2 can't do any of those and just throws an exception.
Carlos
A: 

I would say that such a generic WSDL is utterly useless. There's no contract, no type safety, no advantage to WSDL. What do you learn by examining it? Nothing.

duffymo
Probably true, but I still have to deal with it...
Carlos