android中使用Ksoap2小结

 

http://61.183.41.211:8882/WCFService/BaseDataSettingService.svc?wsdl

结构:

第一部分:引用空间名定义

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:tns="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" name="BaseDataSettingService" targetNamespace="http://tempuri.org/">

第二部分:类和类型定义 

?xsd=xsd0每一个方法的详细描述
?xsd=xsd1序列化用到的数据类型
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://61.183.41.211:8882/WCFService/BaseDataSettingService.svc?xsd=xsd0" namespace="http://tempuri.org/"/>
<xsd:import schemaLocation="http://61.183.41.211:8882/WCFService/BaseDataSettingService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
<xsd:import schemaLocation="http://61.183.41.211:8882/WCFService/BaseDataSettingService.svc?xsd=xsd2" namespace="http://schemas.datacontract.org/2004/07/BaseDataSettingModel"/>
<xsd:import schemaLocation="http://61.183.41.211:8882/WCFService/BaseDataSettingService.svc?xsd=xsd3" namespace="http://schemas.datacontract.org/2004/07/SystemSettingBLL"/>
<xsd:import schemaLocation="http://61.183.41.211:8882/WCFService/BaseDataSettingService.svc?xsd=xsd4" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
</xsd:schema>
</wsdl:types>

第三部分:消息定义,每方法输入、输出信息 

<wsdl:message name="IBaseDataSettingService_SaveYsdmzd_InputMessage">
<wsdl:part name="parameters" element="tns:SaveYsdmzd"/>
</wsdl:message>
<wsdl:message name="IBaseDataSettingService_SaveYsdmzd_OutputMessage">
<wsdl:part name="parameters" element="tns:SaveYsdmzdResponse"/>
</wsdl:message>

第四部分:接口定义,每方法输入、输出信息 

<wsdl:portType name="IBaseDataSettingService">
<wsdl:operation name="Updatemes_master">
<wsdl:input wsaw:Action="http://tempuri.org/IBaseDataSettingService/Updatemes_master" message="tns:IBaseDataSettingService_Updatemes_master_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/IBaseDataSettingService/Updatemes_masterResponse" message="tns:IBaseDataSettingService_Updatemes_master_OutputMessage"/>
</wsdl:operation>
<wsdl:operation name="Dropmes_master">
<wsdl:input wsaw:Action="http://tempuri.org/IBaseDataSettingService/Dropmes_master" message="tns:IBaseDataSettingService_Dropmes_master_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/IBaseDataSettingService/Dropmes_masterResponse" message="tns:IBaseDataSettingService_Dropmes_master_OutputMessage"/>
</wsdl:operation>

第五部分:绑定说明,每方法输入、输出信息 

<wsdl:binding name="BasicHttpBinding_IBaseDataSettingService" type="tns:IBaseDataSettingService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Updatemes_master">
<soap:operation soapAction="http://tempuri.org/IBaseDataSettingService/Updatemes_master" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>

第五部分:服务说明

<wsdl:service name="BaseDataSettingService">
<wsdl:port name="BasicHttpBinding_IBaseDataSettingService" binding="tns:BasicHttpBinding_IBaseDataSettingService">
<soap:address location="http://61.183.41.211:8882/WCFService/BaseDataSettingService.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

kSOAP2使用: 

private WebServiceObject(String url, String nameSpace, String methodName){
        //一般没修改过是http://tempuri.org/  第一部分可找到targetNamespace="http://tempuri.org/" 
        this.nameSpace = nameSpace;
        //创建HttpTransportSE传输对象
    //url第五部分可找到  <soap:address location="http://61.183.41.211:8882/WCFService/BaseDataSettingService.svc"/>
     ht = new HttpTransportSE(url);
        ht.debug = false;
        //创建Envelop对象
    //SoapEnvelope.VER11:对应于SOAP 1.1规范 常量SoapEnvelope.VER12:对应于SOAP 1.2规范
    //第五部分  <soap:address location="http://61.183.41.211:8882/WCFService/BaseDataSettingService.svc"/>
    //soap 对应VER11  soap12对应VER12
    //WCF一般是 VER11,WEBService一般会建两个location,以高版本为准,如果不正确提示  500错误或415错误
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        //创建SoapObject对象
        soapObject = new SoapObject(nameSpace, methodName);
    }

//参数1是soapaction:方法的空间名 从第四部分可找到,如果不正正确提示 500错误
ht.call("http://tempuri.org/IBaseDataSettingService/getBmdmzdList", envelope);

//方法及参数定义可见 http://...?xsd=xsd0
//方法及参数不正确也会 出现 500错误

具体可参考:http://www.cnblogs.com/zhangchaoyang/articles/1955834.html

 

posted on 2015-09-30 16:03  zsfwh  阅读(326)  评论(0)    收藏  举报