如何在Android中传递SOAP请求?

时间:2018-06-07 03:17:38

标签: android soap

我正在尝试像下面这样执行SOAP请求。

 public Request[] getPatronAccountInfo(String appCode, String AppPwd , String patronID) {
Request getAccountInfo = new Request();
SoapObject accountInfoSO = new SoapObject(AppConstants.NAMESPACE, AppConstants.function);
accountInfoSO.addProperty(AppConstants.AppCode, appCode);
accountInfoSO.addProperty(AppConstants.AppPwd, AppPwd);
accountInfoSO.addProperty(AppConstants.ClientIP, "");
accountInfoSO.addProperty(AppConstants.EndUserId, "");
accountInfoSO.addProperty(AppConstants.PatronID, patronID);
accountInfoSO.addProperty(AppConstants.AccessToken, "");

getAccountInfo.setRequestSoapObject(accountInfoSO);
getAccountInfo.setSoapAction(AppConstants.NAMESPACE + "/" + AppConstants.function);
Request[] reqParams = {getAccountInfo};
return reqParams;

}

但我需要在ServiceContext标记之外添加PatronID。

我的SOAP请求是这样的,

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:over="*********">
   <soapenv:Header/>
   <soapenv:Body>
      <over:GetPatronAccountInfoRequest>
         <over:ServiceContext>
            <over:AppCode>123</over:AppCode>
            <over:AppPwd>123</over:AppPwd>
            <over:ClientIP></over:ClientIP>
            <over:EndUserId></over:EndUserId>
         </over:ServiceContext>
         <over:PatronID>1234R</over:PatronID>
         <over:AccessToken></over:AccessToken>
      </over:GetPatronAccountInfoRequest>
   </soapenv:Body>
</soapenv:Envelope>
在ServiceContext标记之外的

我需要传递parans PatronID和AccessToken 如上所述,如何申请这些参赛作品?

1 个答案:

答案 0 :(得分:2)

尝试以下顺序。将getPatronAccountInfo添加到肥皂体中。

SoapObject  getPatronAccountInfo = new SoapObject (NAMESPACE, METHOD_NAME);

SoapObject serviceContext = new SoapObject(NAMESPACE, METHOD_NAME);
serviceContext.addProperty("appcode", "123");
serviceContext.addProperty("AppPwd", "AppPwd");
serviceContext.addProperty("clientIp", "Ip");
serviceContext.addProperty("EndUserId", "Id");

getPatronAccountInfo.addProperty("serviceContext",serviceContext);
getPatronAccountInfo.addProperty("PatronId","1234R");
getPatronAccountInfo.addProperty("AccessToken","token");