首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android没法获取webservice返回的复杂类型数组

2013-07-09 
android无法获取webservice返回的复杂类型数组本帖最后由 wushuangman1127 于 2013-07-03 09:30:25 编辑之

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>


下面是android客户端获取返回值的代码:
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();
                }               


哪位曾写过类似的代码,望给与指点。不胜感激!!! Android Web服务 soap 复杂数组
[解决办法]
貌似webservice只能是返回简单类型的数据,你们自己定义一个格式 ,还是通过string返回,然后按照格式解析不就行了吗
[解决办法]
你获取的返回值通过 envelope.getResponse(); 获取 我没用过这种方式。
这是我们之前用的方式  返回的是字符串,但格式是json格式

HttpTransportSE hts = new HttpTransportSE(URL + serviceName, TIME_OUT);
// 启用调试
hts.debug = true;
SoapSerializationEnvelope sse = new SoapSerializationEnvelope(SoapEnvelope.VER11);
sse.dotNet = true;
sse.bodyOut = request;
hts.call(NAME_SPACE + nsService + method, sse);



// 返回结果
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,解析就简单了撒

热点排行