Webservice 访问 随笔记载

// logInfo 为例 ,实现KvmSerializable 接口,

// Webservice 连接

private SoapObject posted(LogInfo info) {

SoapObject request = new SoapObject(NameSapce, PostedMethod);
PropertyInfo argument = new PropertyInfo();
argument.setName("postLog"); //对应参数名称 
argument.setValue(info);
argument.setType(LogInfo.class);
request.addProperty(argument);


SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
HttpTransportSE ht = new HttpTransportSE(Constant.webServiceAddress2);
envelope.addMapping(LogInfo.NAMESPACE, "logInfo", LogInfo.class);  // 第一个参数为命名空间,第二个为类型,与wsdl中的相同
envelope.dotNet = true;
envelope.bodyOut = ht;
envelope.setOutputSoapObject(request);
ht.debug = true;
try {
ht.call(NameSapce + PostedMethod, envelope);
System.out.println("posted-------------->" + ht.requestDump);
SoapObject message = (SoapObject) envelope.getResponse();
return message;
} catch (HttpResponseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
return null;

}


// 服务器

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <PostLog xmlns="http://tempuri.org/">
      <postLog>  ------- 参数名称
        <PostedUser>string</PostedUser>
        <EventID>string</EventID>
        <Desc>string</Desc>
        <Pic>string</Pic>
        <P1>string</P1>
        <P2>string</P2>
        <P3>string</P3>
        <C1>string</C1>
        <C2>string</C2>
        <T1>string</T1>
        <T2>string</T2>
        <M1>string</M1>
        <Treatment>string</Treatment>
        <DateRepair1>string</DateRepair1>
        <DateRepair2>string</DateRepair2>
      </postLog>
    </PostLog>
  </soap:Body>
</soap:Envelope>
 
 
<s:complexType name="logInfo"> ---- addMapping方法的第二个参数
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="PostedUser" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="EventID" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Desc" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Pic" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="P1" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="P2" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="P3" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="C1" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="C2" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="T1" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="T2" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="M1" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Treatment" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="DateRepair1" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="DateRepair2" type="s:string"/>
</s:sequence>
</s:complexType>
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值