android无法获取webservice返回的复杂类型数组
本帖最后由 wushuangman1127 于 2013-07-03 09:30:25 编辑 之前返回的是String,可以获取到返回值,现在返回的复杂数组,我尝试了几天都没有成功,获取的都是空。webservice接口如下:
<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://localhost/soap/myswdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://localhost/soap/myswdl">
<types>
<xsd:schema targetNamespace="http://localhost/soap/myswdl"
>
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" />
<xsd:complexType name="Customer">
<xsd:all>
<xsd:element name="phone" type="xsd:string"/>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="long" type="xsd:float"/>
<xsd:element name="lat" type="xsd:float"/>
<xsd:element name="speed" type="xsd:float"/>
<xsd:element name="direction" type="xsd:string"/>
<xsd:element name="company" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="CustomerArray">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:Customer[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
</types>
<message name="findcustomerRequest">
<part name="long" type="xsd:float" />
<part name="lat" type="xsd:float" />
<part name="longrange" type="xsd:float" />
<part name="latrange" type="xsd:float" />
<part name="pin" type="xsd:string" /></message>
<message name="findcustomerResponse">
<part name="return" type="tns:CustomerArray" /></message>
<portType name="myswdlPortType">
<operation name="findcustomer">
<input message="tns:findcustomerRequest"/>
<output message="tns:findcustomerResponse"/>
</operation>
</portType>
<binding name="myswdlBinding" type="tns:myswdlPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="findcustomer">
<soap:operation soapAction="http://localhost/taxi/s_findcustomer.php/findcustomer" style="rpc"/>
<input><soap:body use="encoded" namespace="" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>
<output><soap:body use="encoded" namespace="" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>
</operation>
</binding>
<service name="myswdl">
<port name="myswdlPort" binding="tns:myswdlBinding">
<soap:address location="http://localhost/taxi/s_findcustomer.php"/>
</port>
</service>
</definitions>
String nameSpace = "http://localhost/soap/myswdl";
String soapAction = "http://localhost/taxi/s_findtaxi.php/findtaxi";
String methodName = "findtaxi";
String endPoint = "http://localhost/taxi/s_findtaxi.php";
Vector<SoapObject> result=null;
SoapObject object = null;
SoapObject request = new SoapObject(nameSpace,methodName);
request.addProperty("long",lng);
request.addProperty("lat",lat);
request.addProperty("longrange",longrange);
request.addProperty("latrange",latrange);
request.addProperty("pin","1111");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
HttpTransportSE androidHttpTransport = new HttpTransportSE(endPoint);
try {
androidHttpTransport.call(null, envelope);
if (envelope.getResponse() != null)
{
object = (SoapObject)envelope.bodyIn;
result = (Vector) object.getProperty("return");
}
}catch (Exception e) {
e.printStackTrace();
}
// 返回结果
SoapObject response = null;
response = (SoapObject) sse.bodyIn;
String result = null;
try {
result = response.getProperty(0).toString();
} catch (Exception e) {
throw new UnknowException("返回数据为空");
}
返回通过sse.bodyIn这个方式获取 ,你试试呢,如果response 不为null,解析就简单了撒