WSDL返回什么格式?

时间:2013-02-02 19:48:38

标签: android wsdl

我正在制作一个Android应用程序,需要访问基于在线WSDL的数据库。我的代码从该数据库访问国家列表,但我不知道我将获取数据的格式。例如。一个字符串,一个数组?等等。那么WSDL有任何标准的返回类型吗?感谢。

编辑:代码段

        //this is the actual part that will call the webservice
        androidHttpTransport.call(SOAP_ACTION, envelope);

        // Get the SoapResult from the envelope body.
        SoapObject result = (SoapObject)envelope.bodyIn;

    if(result!=null)
    {
        //put the value in an array
        // prepare the list of all records
         List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
        for(int i = 0; i < 10; i++){
            HashMap<String, String> map = new HashMap<String, String>();
            map.put(result.getProperty(i).toString());
            fillMaps.add(map);
            lv.setOnItemClickListener(onListClick);
        }
     // fill in the grid_item layout
        SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.grid_item, from, to);
        lv.setAdapter(adapter);
    }
        else
        {
              Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_LONG).show();
        }
  } catch (Exception e) {
        e.printStackTrace();
  }

1 个答案:

答案 0 :(得分:1)

WSDL本身不是数据格式。它是基于XML的Web服务合同描述。使用WSDL定义输入参数和结果输出。见WSDL

使用XML架构定义(XSD)定义数据。见XSD

我对Android不熟悉,但应该有一些库支持或第三方工具来读取WSDL定义并创建代表客户端代理的java类。

(更新) 响应返回一种“国家”

<message name="getCountryListResponse">
 <part name="return" type="tns:Countries"/>
</message>

如果查看“Countries”类型,它就是一个数组 “国家”类型:

<xsd:complexType name="Countries">
<xsd:complexContent> 
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute wsdl:arrayType="tns:Country[]" ref="SOAP-ENC:arrayType"/>
 </xsd:restriction> 
</xsd:complexContent> 

“国家”类型有以下三个元素。

</xsd:complexType> -
<xsd:complexType name="Country">
<xsd:all> 
<xsd:element name="coid" type="xsd:int"/>
<xsd:element name="countryName" type="xsd:string"/> 
<xsd:element name="countryCode" type="xsd:string"/>
</xsd:all>
</xsd:complexType>

所以,如果你的android代码没有创建客户端代理, 你需要解析XML的数据,如上所示。

它可能看起来像(简化):

<Countries>
  <Country>
    <coid>123</coid>
    <countryName>France</countryName>
    <countryCode>111</countryCode>
</Countries>
相关问题