使用Apache Axis2开发Web服务

时间:2012-03-01 14:38:01

标签: web-services java-ee wsdl axis2

我使用Apache Axis2开发了webservice,WSDL文件接受了ArrayList数据结构。但是,在WSDL文件中,它显示数据结构的类型,如下所示:

<xs:complexType>
 <xs:sequence>
  <xs:element minOccurs="0" name="myDetails" nillable="true" type="xs:anyType" /> 
 </xs:sequence>
</xs:complexType>

我正在尝试使用基于生成的WSDL文件的Apache Axis2生成客户端类。我正在尝试转发ArrayList详细信息,如下所示:

ArrayList<String> myDetails = new ArrayList<String>();
myDetails.add("param1,param2,param3");

将以上的arraylist转发为Client类的myDetails.toArray(),如下所示:

WebserviceStub ws = new WebserviceStub("http://localhost:8080/Service/services");
CustomerDetails cd = new CustomerDetails();
cd.setMyDetails(myDetails.toArray());
CustomerDetailsResponse cds = ws.customerDetails(cd);

如果我将上述客户端类作为Java Application运行,那么它将显示以下错误消息:

[INFO] Unable to sendViaPost to url[http://localhost:8080/Service/services/]
org.apache.axis2.AxisFault: Unknow type can not serialize
    at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
    at org.apache.axis2.transport.http.SOAPMessageFormatter.writeTo(SOAPMessageFormatter.java:83)
    at org.apache.axis2.transport.http.AxisRequestEntity.writeRequest(AxisRequestEntity.java:84)
    at org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:499)
    at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2114)
    at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
    at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
    at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)
    at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:557)
    at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:199)
    at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:76)
    at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:400)
    at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:225)
    at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:438)
    at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:402)
    at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
    at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
Caused by: javax.xml.stream.XMLStreamException: Unknow type can not serialize
    at org.apache.axis2.databinding.utils.ConverterUtil.serializeAnyType(ConverterUtil.java:1456)
    at org.apache.axis2.databinding.ADBDataSource.serialize(ADBDataSource.java:93)
    at org.apache.axiom.om.impl.llom.OMSourcedElementImpl.internalSerialize(OMSourcedElementImpl.java:695)
    at org.apache.axiom.om.impl.util.OMSerializerUtil.serializeChildren(OMSerializerUtil.java:563)
    at org.apache.axiom.om.impl.llom.OMElementImpl.internalSerialize(OMElementImpl.java:874)
    at org.apache.axiom.soap.impl.llom.SOAPEnvelopeImpl.serializeInternally(SOAPEnvelopeImpl.java:283)
    at org.apache.axiom.soap.impl.llom.SOAPEnvelopeImpl.internalSerialize(SOAPEnvelopeImpl.java:245)
    at org.apache.axiom.om.impl.llom.OMSerializableImpl.serializeAndConsume(OMSerializableImpl.java:193)
    at org.apache.axis2.transport.http.SOAPMessageFormatter.writeTo(SOAPMessageFormatter.java:79)
    ... 19 more

我们可以使用Axis2将ArrayList作为参数传递给webservice吗?它有任何限制吗?任何想法将不胜感激

1 个答案:

答案 0 :(得分:0)

在Web服务上使用ArrayList的方式

1.它支持更多Set on a collection list in collection Class。

2.您需要使用@XmlRootElement在服务器端创建Serialized Class并提供此数组getter和setter 客户端和用户端都要序列化......

相关问题