worklight中adapter(webservice)

找个webservice的接口,如:http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl

用soupUI打开,使用第一个接口,如:

  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://WebXml.com.cn/">
   <soapenv:Header/>
   <soapenv:Body>
      <web:getMobileCodeInfo>
         <!--Optional:-->
         <web:mobileCode>?</web:mobileCode>
         <!--Optional:-->
         <web:userID>?</web:userID>
      </web:getMobileCodeInfo>
   </soapenv:Body>
</soapenv:Envelope> 
?部分为填入的参数。
写test.xml,如:

<?xml version="1.0" encoding="UTF-8"?>
<!--
    Licensed Materials - Property of IBM
    5725-G92 (C) Copyright IBM Corp. 2011, 2013. All Rights Reserved.
    US Government Users Restricted Rights - Use, duplication or
    disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
-->
<wl:adapter name="test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:wl="http://www.worklight.com/integration"
xmlns:http="http://www.worklight.com/integration/http">


<displayName>test</displayName>
<description>test</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol> http</protocol>
<domain> webservice.webxml.com.cn</domain>
<port> 80</port>
<!-- Following properties used by adapter's key manager for choosing specific certificate from key store  
<sslCertificateAlias></sslCertificateAlias> 
<sslCertificatePassword></sslCertificatePassword>
-->
</connectionPolicy>
<loadConstraints maxConcurrentConnectionsPerNode="2" />
</connectivity>

<procedure name="getStories"/>

</wl:adapter>

在test-impl.js中,如:

/**
 * @param interest
 *            must be one of the following: world, africa, sport, technology, ...
 *            (The list can be found in http://edition.cnn.com/services/rss/)
 * @returns json list of items
 */
function getStories() {

//这部分与soupUI看的是相同的
var contentRequest = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"http://WebXml.com.cn/\">";
contentRequest += "<soapenv:Header/>";
contentRequest += "<soapenv:Body>";
contentRequest += "<web:getMobileCodeInfo>";
contentRequest += "<web:mobileCode>0</web:mobileCode>";
contentRequest += "<web:userID>0</web:userID>";
contentRequest += "</web:getMobileCodeInfo>"; 
contentRequest += "</soapenv:Body>";
contentRequest += "</soapenv:Envelope>";



var input = {
   method : 'get',
   returnedContentType : 'xml',
   path : "/WebServices/MobileCodeWS.asmx?wsdl",
   body : {
content : contentRequest.toString(),
contentType : 'text/xml; charset=utf-8'
},
};

var baseDatares=WL.Server.invokeHttp(input);
return baseDatares;
}

这样就可以获取到接口里的数据了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值