Android SOAP Object引用设置为对象的实例

时间:2018-03-09 12:24:58

标签: android soap android-ksoap2

我需要使用SOAP而不是REST。到目前为止,我在这里和youtube上都遵循了SOAP和kSOAP2教程和线程。

这是获取请求密钥的Web服务。我没有任何错误地完成了这个。我使用时间格式添加RequestValid和当前时间:“dd:MM:yyyy HH:mm”并检索对当前分钟有效的请求密钥(身份验证令牌)。

网址:http://mobileexam.veripark.com/mobileforeks/service.asmx

请求

<?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>
    <Encrypt xmlns="http://tempuri.org/">
      <request>RequestIsValid29:01:2015 16:31</request>
    </Encrypt>
  </soap:Body>
</soap:Envelope>

响应

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope 
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <EncryptResponse 
            xmlns="http://tempuri.org/">
         <EncryptResult>%%UmVxdWVzdElzVmFsaWQyOTowMToyMDE1IDE2OjMx%%</EncryptResult>
        </EncryptResponse>
    </soap:Body>
</soap:Envelope>

我只添加必要的代码来检索请求密钥。

private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://mobileexam.veripark.com/mobileforeks/service.asmx";
private static final String METHOD_NAME_ENCRYPT = "Encrypt";
private static final String SOAP_ACTION_ENCRYPT = NAMESPACE + METHOD_NAME_ENCRYPT;

public void getRequestKey() {
    SoapObject soapObject = new SoapObject(NAMESPACE, METHOD_NAME_ENCRYPT);
    soapObject.addProperty("request", "RequestIsValid10:03:2018 16:30");
}

接下来,使用请求密钥我需要获取数据,但我无法理解Web服务的格式和我想的正确属性。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:GetForexStocksandIndexesInfo>
         <tem:request>
            <tem:IsIPAD>true</tem:IsIPAD>
            <tem:DeviceID>test</tem:DeviceID>
            <tem:DeviceType>ipad</tem:DeviceType>
            <tem:RequestKey>%%UmVxdWVzdElzVmFsaWQxNjowNToyMDEyIDExOjU4%%</tem:RequestKey>
            <tem:Period>Month</tem:Period>
         </tem:request>
      </tem:GetForexStocksandIndexesInfo>
   </soapenv:Body>
</soapenv:Envelope>

标记封装属性而不是基元时出错。直接添加属性显然不正确。

    SoapObject soapObject = new SoapObject(NAMESPACE, METHOD_NAME_FOREX);
    soapObject.addProperty("IsIPAD", "true");
    soapObject.addProperty("DeviceID", "test");
    soapObject.addProperty("DeviceType", "ipad");
    soapObject.addProperty("RequestKey", requestKey);
    soapObject.addProperty("Period", "Month");

返回Message=Object reference not set to an instance of an object

我还尝试添加属性,使用KvmSerializable类添加属性PropertyInfo,但没有任何作用。

如果你能为这项服务提供一个有效的例子,我将不胜感激。

0 个答案:

没有答案