AXIS2客户端返回带有空值而不是属性的对象

时间:2011-05-05 17:06:31

标签: java web-services axis2

我有这样的结构,我需要通过webService返回

public class StructureClass implements Serializable
{

    public StructureClass()
    {
        exampleFIO = new FIO();
    }
    public FIO exampleFIO;
    public String result;
}

public class FIO implements Serializable{

    public String FirstName;
    public String LastName;

}

WebService应用程序:

public class ReturnObject {
    public StructureClass retObject()
    {
        StructureClass structClassObject = new StructureClass();
        structClassObject.exampleFIO.FirstName = "A";
        structClassObject.exampleFIO.LastName = "G";
        structClassObject.result = "good";
        return structClassObject;
    }
}

我在AXIS2和Eclipse

的帮助下构建了webservice应用程序

WSDL是:

*<wsdl:definitions targetNamespace="http://objectreturn.xxxxxx.com">
<wsdl:documentation>
        Please Type your service description here
    </wsdl:documentation>
−
<wsdl:types>
−
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://objectreturn.xxxxxx.com/xsd">
−
<xs:complexType name="StructureClass">
<xs:sequence/>
</xs:complexType>
</xs:schema>
−
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://objectreturn.xxxxxx.com">
<xs:import namespace="http://objectreturn.xxxxxx.com/xsd"/>
−
<xs:element name="retObjectResponse">
−
<xs:complexType>
−
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="ax22:StructureClass"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="retObjectRequest"/>
−
<wsdl:message name="retObjectResponse">
<wsdl:part name="parameters" element="ns:retObjectResponse"/>
</wsdl:message>
−
<wsdl:portType name="ReturnObjectPortType">
−
<wsdl:operation name="retObject">
<wsdl:input message="ns:retObjectRequest" wsaw:Action="urn:retObject"/>
<wsdl:output message="ns:retObjectResponse" wsaw:Action="urn:retObjectResponse"/>
</wsdl:operation>
</wsdl:portType>
−
<wsdl:binding name="ReturnObjectSoap11Binding" type="ns:ReturnObjectPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
−
<wsdl:operation name="retObject">
<soap:operation soapAction="urn:retObject" style="document"/>
−
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
−
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
−
<wsdl:binding name="ReturnObjectSoap12Binding" type="ns:ReturnObjectPortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
−
<wsdl:operation name="retObject">
<soap12:operation soapAction="urn:retObject" style="document"/>
−
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
−
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
−
<wsdl:binding name="ReturnObjectHttpBinding" type="ns:ReturnObjectPortType">
<http:binding verb="POST"/>
−
<wsdl:operation name="retObject">
<http:operation location="ReturnObject/retObject"/>
−
<wsdl:input>
<mime:content type="text/xml" part="retObject"/>
</wsdl:input>
−
<wsdl:output>
<mime:content type="text/xml" part="retObject"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
−
<wsdl:service name="ReturnObject">
−
<wsdl:port name="ReturnObjectHttpSoap11Endpoint" binding="ns:ReturnObjectSoap11Binding">
<soap:address location="http://localhost:8080/XXXXXX/services/ReturnObject.ReturnObjectHttpSoap11Endpoint/"/>
</wsdl:port>
−
<wsdl:port name="ReturnObjectHttpSoap12Endpoint" binding="ns:ReturnObjectSoap12Binding">
<soap12:address location="http://localhost:8080/XXXXXX/services/ReturnObject.ReturnObjectHttpSoap12Endpoint/"/>
</wsdl:port>
−
<wsdl:port name="ReturnObjectHttpEndpoint" binding="ns:ReturnObjectHttpBinding">
<http:address location="http://localhost:8080/XXXXXX/services/ReturnObject.ReturnObjectHttpEndpoint/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>*

当我尝试在客户的帮助下调用它时

RPCServiceClient serviceClient = new RPCServiceClient();
            Options options = serviceClient.getOptions();

            EndpointReference targetEPR = new EndpointReference(
                    "http://localhost:8080/XXXXXX/services/ReturnObject");
            options.setTo(targetEPR);

            options.setAction("sendAttachment");

            QName opGetObject = new QName("http://objectreturn.xxxxxx.com", "retObject");
            Object[] opSetArgs = new Object[] { };
            Class[] returnTypes = new Class[] { StructureClass.class };

            Object[] returnArray = serviceClient.invokeBlocking(opGetObject,
                    opSetArgs, returnTypes);


        StructureClass xx = (StructureClass)returnArray[0];

        System.out.println(xx.result);

我为 xx

类的所有属性获得 null

请你帮忙解决可能存在的问题。

谢谢, 安德鲁

1 个答案:

答案 0 :(得分:0)

检查Axis2 Apache Tutorial并根据教程执行代码。

(例如,从类中删除实现Serializable,除非你真的需要它,在类中创建getter和setter方法)