1
我從2天開始工作,已經在這裏搜索了教程和其他問題,但是我沒有做到。 問題是:代碼似乎是有效的,我將它與其他人進行了比較,但我未能達到我的web服務的「正確答案」。這是該活動的代碼:我收到一個答案,但不正確Android:將myApp與webService連接
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是
收到代碼:「掃描結果」
這是一個字符串。
這是web服務的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>
(先來一些預先檢查:檢查你是否有網絡權限,檢查你的電話到達服務器的android網絡瀏覽器等等) 你是否嘗試設置'SoapSerializationEnvelope.dotNet'爲true? – Kalem
設置Internet權限;我如何使用手機查看?我已經嘗試使用Chrome或我的手機上的默認瀏覽器打開網址,它可以正常工作。 已經設置「envelope.dotNet = true」。 – Marco