1

我正在尝试使用https://swea.riksbank.se/sweaWS/wsdl/sweaWS_ssl.wsdl中描述的网络服务

我编写了以下测试代码:

private static final String NAMESPACE = "http://swea.riksbank.se/ws";
private static final String METHOD_NAME = "getInterestAndExchangeGroupNames";
private static final String SOAP_ACTION = NAMESPACE + "/" + METHOD_NAME;
private static final String URL = "https://swea.riksbank.se:443/sweaWS/services/SweaWebServiceHttpSoap12Endpoint";

private void testService(){

    HttpTransportSE androidHttpTransport = null;

    try {
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        PropertyInfo groupid = new PropertyInfo();
        groupid.setValue(5);
        groupid.setType(PropertyInfo.INTEGER_CLASS);
        groupid.setName("groupid");

        PropertyInfo languageid = new PropertyInfo();
        languageid.setValue("sv");
        languageid.setType(PropertyInfo.STRING_CLASS);
        languageid.setName("languageid");

        request.addProperty(groupid);
        request.addProperty(languageid);

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
        envelope.dotNet = false;
        envelope.setOutputSoapObject(request);

        androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.debug = true;
        androidHttpTransport.call(SOAP_ACTION, envelope);
        //SoapObject result = (SoapObject)envelope.getResponse();
    }
    catch (Exception e) {
        Log.e("SOAP_TEST", "========= Request start =========");
        Log.e("SOAP_TEST", androidHttpTransport.requestDump);
        Log.e("SOAP_TEST", "========== Request end ==========");
        Log.e("SOAP_TEST", "========= Response start ========");
        Log.e("SOAP_TEST", androidHttpTransport.responseDump);
        Log.e("SOAP_TEST", "========== Response end =========");

        Log.e("SOAP_TEST", e.toString());
        Log.e("SOAP_TEST", e.getMessage());
    }
}

测试代码将导致 HTTP 状态 500

当我检查请求转储时,请求 xml 如下所示:

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://www.w3.org/2003/05/soap-encoding" xmlns:v="http://www.w3.org/2003/05/soap-envelope">
<v:Header />
<v:Body>
    <n0:getInterestAndExchangeGroupNames id="o0" c:root="1" xmlns:n0="http://swea.riksbank.se/ws">
        <groupid i:type="d:int">5</groupid>
        <languageid i:type="d:string">sv</languageid>
    </n0:getInterestAndExchangeGroupNames>
    </v:Body>
</v:Envelope>

我还将 wsdl 导入到 soapUI 中,这将生成以下请求:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://swea.riksbank.se/xsd">
   <soap:Header/>
   <soap:Body>
      <xsd:getInterestAndExchangeNames>
         <groupid>5</groupid>
         <languageid>sv</languageid>
      </xsd:getInterestAndExchangeNames>
   </soap:Body>
</soap:Envelope>

该请求看起来与 Web 服务文档中的描述完全相同,并且也可以按预期工作。

那么我需要做什么来修复 ksoap2 请求?(这种肥皂对我来说是全新的。)

4

1 回答 1

1

经过一些更新后,它现在可以正常工作了。我的工作测试代码如下所示:

private static final String NAMESPACE = "http://swea.riksbank.se/xsd";
private static final String METHOD_NAME = "getInterestAndExchangeNames";
private static final String SOAP_ACTION = NAMESPACE + "/" + METHOD_NAME;
private static final String SOAP_URL = "https://swea.riksbank.se:443/sweaWS/services/SweaWebServiceHttpSoap12Endpoint";

private void testService(){

    HttpTransportSE androidHttpTransport = null;

    try {
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        PropertyInfo groupid = new PropertyInfo();
        groupid.setValue(5);
        groupid.setName("groupid");
        groupid.setNamespace("");

        PropertyInfo languageid = new PropertyInfo();
        languageid.setValue("sv");
        languageid.setName("languageid");
        languageid.setNamespace("");

        request.addProperty(groupid);
        request.addProperty(languageid);

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
        envelope.encodingStyle = SoapEnvelope.ENC;
        envelope.setAddAdornments(false);
        envelope.implicitTypes = true;
        envelope.dotNet = false;
        envelope.setOutputSoapObject(request);

        androidHttpTransport = new HttpTransportSE(SOAP_URL);
        androidHttpTransport.debug = true;
        androidHttpTransport.call(SOAP_ACTION, envelope);

        ...
    }
于 2013-06-05T21:36:46.570 回答