I generated a lot of classes using Apache Axis based on a WSDL for a .NET SOAP web service. The generated methods for the web methods return Result classes that just have some generic org.apache.axis.message.MessageElement[] value. I instead want a Result class that corresponds perfectly to the XML that the web method returns. I used JAX to create a couple Java classes based on the XSD for the XML returned by one of my web methods, and those generated classes are annotated and have properties that match my XML:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"content"
})
@XmlRootElement(name = "fields")
public class Fields {
@XmlValue
protected String content;
@XmlAttribute(required = true)
@XmlSchemaType(name = "anySimpleType")
protected String parameters;
public String getContent() {
return content;
}
public void setContent(String value) {
this.content = value;
}
public String getParameters() {
return parameters;
}
public void setParameters(String value) {
this.parameters = value;
}
}
I’m now trying to integrate the JAX classes, like Fields above, into the Result class that Apache Axis generated. I don’t know how to go about this. The Apache Axis-generated class has the following methods that might be useful:
public static org.apache.axis.encoding.Serializer getSerializer(
java.lang.String mechType, java.lang.Class _javaType,
javax.xml.namespace.QName _xmlType) {
return new org.apache.axis.encoding.ser.BeanSerializer(_javaType,
_xmlType, typeDesc);
}
public static org.apache.axis.encoding.Deserializer getDeserializer(
java.lang.String mechType, java.lang.Class _javaType,
javax.xml.namespace.QName _xmlType) {
return new org.apache.axis.encoding.ser.BeanDeserializer(_javaType,
_xmlType, typeDesc);
}
Can I somehow take the MessageElement[] that comes into my Result class constructor (its only parameter), and populate the a Fields instance, based on how Fields is annotated with @XmlRootElement and the like? Or did something go awry when generating the Apache Axis classes based on my .NET WSDL, to cause the generated Result classes to be so generic?
Edit: Michael’s comment made me check the WSDL, and it has this bit in wsdl:types:
<s:element name="MyResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="MyResult">
<s:complexType mixed="true">
<s:sequence>
<s:any/>
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
That’s all the mention I saw of MyResult, and that complexType / sequence / any looks pretty generic. Maybe I need to do something more with my .NET web service, then generate Java classes with Axis.
Michael’s comment about checking the WSDL pointed me in the right direction. A couple of my web methods were just returning
XmlDocument, so the WSDL was very generic about them. I changed the web methods to return custom classes with the[Serializable]attribute and now the WSDL is more specific, so the Axis-generated code is more specific.