我从2天开始工作,已经在这里搜索了教程和其他问题,但我没有做到。 问题是:代码似乎有效,我将其与其他人进行了比较,但我未能达到"正确答案"来自我的网络服务。这是活动的代码:
public void connect() {
String scanResult = result.getContents();
String URL = "http://192.168.1.10/wsatena/GestioneDatiVisitatore.asmx";
String NAMESPACE = "http://atenainfo.it/serviziweb/";
String METHOD_NAME = "TestWebService";
String SOAP_ACTION = NAMESPACE + METHOD_NAME;
SoapObject request = null, objMessages = null;
SoapSerializationEnvelope envelope;
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//envelope.implicitTypes = true;
request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo propertyInfo = new PropertyInfo();
propertyInfo.setName("idProgrForm");
propertyInfo.setValue(scanResult);
propertyInfo.setType(String.class);
request.addProperty(propertyInfo);
envelope.implicitTypes = true;
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
envelope.setAddAdornments(false);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
//Get the response
Object response = envelope.getResponse();
String result = response.toString();
}
catch (Exception e) {
}
}
我收到了答案,但不正确,事实上我得到了:
收到的代码:
没有我传递的代码"请求"宾语。 我用SoapUI测试的正确响应是
收到的代码:"扫描结果"
这是一个字符串。
这是webService的xml:
TestWebService
Test
The test form is only available for requests from the local machine.
SOAP 1.1
The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.
POST /wsatena/GestioneDatiVisitatore.asmx HTTP/1.1
Host: 192.168.1.10
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://atenainfo.it/serviziweb/TestWebService"
<?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>
<TestWebService xmlns="http://atenainfo.it/serviziweb">
<idProgrForm>string</idProgrForm>
</TestWebService>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?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>
<TestWebServiceResponse xmlns="http://atenainfo.it/serviziweb">
<TestWebServiceResult>string</TestWebServiceResult>
</TestWebServiceResponse>
</soap:Body>
</soap:Envelope>
SOAP 1.2
The following is a sample SOAP 1.2 request and response. The placeholders shown need to be replaced with actual values.
POST /wsatena/GestioneDatiVisitatore.asmx HTTP/1.1
Host: 192.168.1.10
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<TestWebService xmlns="http://atenainfo.it/serviziweb">
<idProgrForm>string</idProgrForm>
</TestWebService>
</soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<TestWebServiceResponse xmlns="http://atenainfo.it/serviziweb">
<TestWebServiceResult>string</TestWebServiceResult>
</TestWebServiceResponse>
</soap12:Body>
</soap12:Envelope>
答案 0 :(得分:0)
<强>解决:强> 需要在我的网络服务上加上“/”,这里写的CODE很好。