一直试图让Ksoap2调用在vb.net中创建的简单web服务但返回错误,我已经能够追踪我的Android代码,并在响应中发现了这个错误代码,“System.Web.Services.Protocols。 SoapException:服务器无法识别HTTP Header SOAPAction的值“。 当我在浏览器中调用相同的webservice方法时,我注意到实际的SOAP响应不包含SOAP Header,那会是问题的原因吗?
提前感谢任何建议。
private static final String SOAP_ACTION = "http://192.168.1.105/Service1.asmx/TestQuery";
private static final String METHOD_NAME = "TestQuery";
private static final String NAMESPACE = "http://localhost/";
private static final String URL = "http://192.168.1.105/Service1.asmx";
public void call()
{
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
Toast.makeText(this, METHOD_NAME, Toast.LENGTH_LONG).show();
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
TV1.setText("Error: " + androidHttpTransport.requestDump);
androidHttpTransport.call(SOAP_ACTION, envelope);
Object result = (Object)envelope.getResponse();
Toast.makeText(this, result.toString(), Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
}