我是android和ws的新手。我有一个jboss服务器,其中我使用注释公开了一些Web服务。我使用ksoap2库来使用该Web服务,但它抛出了RunTimeException:无法序列化错误。
WSDL:
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="AccountOperationService" targetNamespace="http://provider.account.com/Version1" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://provider.account.com/Version1" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<types>
<xs:schema targetNamespace="http://provider.account.com/Version1" version="1.0" xmlns:tns="http://provider.account.com/Version1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="CreateException" type="tns:CreateException"/>
<xs:element name="getAccountDetail" type="tns:getAccountDetail"/>
<xs:complexType name="init">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="initResponse">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="CreateException">
<xs:sequence>
<xs:element minOccurs="0" name="message" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="getAccountDetail">
<xs:sequence>
<xs:element minOccurs="0" name="arguments" type="tns:getAccountDetailRequestVO"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="getAccountDetailRequestVO">
<xs:sequence>
<xs:element name="accountNumber" type="xs:string"/>
<xs:element name="balanceInfoRequired" nillable="true" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="getAccountDetailResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="tns:accountDetailResponseVO"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="accountDetailResponseVO">
<xs:complexContent>
<xs:extension base="tns:integrationBaseResponse">
<xs:sequence>
<xs:element minOccurs="0" name="accountVOs" nillable="true" type="tns:accountResponseVO"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="accountResponseVO">
<xs:complexContent>
<xs:extension base="tns:integrationBaseResponse">
<xs:sequence>
<xs:element name="accountNumber" type="xs:string"/>
<xs:element minOccurs="0" name="firstName" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="lastName" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="password" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="userName" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
</types>
<message name="AccountOperation_getAccountDetail">
<part element="tns:getAccountDetail" name="getAccountDetail"/>
</message>
<operation name="getAccountDetail" parameterOrder="getAccountDetail">
<input message="tns:AccountOperation_getAccountDetail"/>
<output message="tns:AccountOperation_getAccountDetailResponse"/>
</operation>
</portType>
<binding name="AccountOperation" type="tns:AccountOperation">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getAccountDetail">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="AccountOperationService">
<port binding="tns:AccountOperationBinding" name="AccountOperationPort">
<soap:address location="http://10.110.1.98:8080/account/AccountOperationsWebService/AccountOperationService/AccountOperation"/>
</port>
</service>
</definitions>
Java代码:
String METHOD_NAME = "getAccountDetail";
String NAMESPACE = "http://provider.account.com/Version1";
String URL = "http://10.110.1.98:8080/account/AccountOperationsWebService/AccountOperationService/AccountOperation?wsdl";
String SOAP_ACTION = NAMESPACE+ METHOD_NAME;
String response = null;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo p1 = new PropertyInfo();
p1.setName("accountNumber");
p1.setType(String.class);
p1.setValue("ACCM561680");
request.addProperty("arguments",p1);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
androidHttpTransport.call(SOAP_ACTION, envelope);
try
{
SoapObject responsePM = (SoapObject) envelope.getResponse();
response = responsePM.toString();
} catch (Exception e)
{
e.printStackTrace();
response = "Error occured";
}
System.out.println(response);
} catch (Exception aE)
{
System.out.println(aE.toString());
aE.printStackTrace();
}
return response;
例外:
java.lang.RuntimeException: Cannot serialize: accountNumber : ACCM561680
java.lang.RuntimeException: Cannot serialize: accountNumber : ACCM561680
at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:664)
at org.ksoap2.serialization.SoapSerializationEnvelope.writeProperty(SoapSerializationEnvelope.java:649)
at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:604)
at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:582)
at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:658)
at org.ksoap2.serialization.SoapSerializationEnvelope.writeBody(SoapSerializationEnvelope.java:564)
at org.ksoap2.SoapEnvelope.write(SoapEnvelope.java:205)
at org.ksoap2.transport.Transport.createRequestData(Transport.java:111)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:121)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:96)
at MyBackgroundTask_Billing2.doInBackground(MyBackgroundTask_Billing2.java:33)
at MyBackgroundTask_Billing2.main(MyBackgroundTask_Billing2.java:55)
提前致谢