我正在尝试使用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请求呢? (这种肥皂对我来说是全新的。)
答案 0 :(得分: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);
...
}