gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 05:45:57 24 4
gpt4 key购买 nike

我有这样的结构,我需要通过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;

}

Web服务应用程序:

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 的帮助下构建了 Web 服务应用程序

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

您能帮忙解决一下这里可能出现的问题吗?

谢谢,安德鲁

最佳答案

检查Axis2 Apache Tutorial并按照教程编写代码。

(例如,从类中删除实现 Serialized,除非您确实需要它,否则在类中创建 getter 和 setters 方法)

关于java - AXIS2 客户端返回带有空值而不是属性的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5901562/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com