加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Webservice 访问 随笔记载

发布时间:2020-12-16 23:13:14 所属栏目:安全 来源:网络整理
导读:// logInfo 为例 ,实现KvmSerializable 接口, // Webservice 连接 private SoapObject posted(LogInfo info) { SoapObject request = new SoapObject(NameSapce,PostedMethod); PropertyInfo argument = new PropertyInfo(); argument.setName("postLog");

// 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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读