Добрый день всем.
Я пытаюсь сделать SOAP-вызов для .net WebServer, работающего локально, но я думаю, что что-то упустил. Код Android мне кажется нормальным. Возможно, SOAP-запрос неверен ...
Вот что дает веб-сервер для метода, который я пытаюсь вызвать:
POST /WebAvanza/WebAvanzaInterface.asmx HTTP/1.1
Host: localhost
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>
<InitTransazione xmlns="http://tempuri.org/">
<ip>string</ip>
<codice>string</codice>
</InitTransazione>
</soap12:Body>
</soap12:Envelope>
и вот что я написал до сих пор:
private String InitTransaction(String command){
String NAMESPACE = "http://tempuri.org/";
String METHOD_NAME = "InitTransazione";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("ip", ipAddress);
request.addProperty("codice", command);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(URL);
httpTransport.debug = true;
String SOAP_ACTION = NAMESPACE + METHOD_NAME;
Object result = null;
try {
httpTransport.call(SOAP_ACTION, envelope);
result = envelope.getResponse();
}
catch(Exception e)
{
e.printStackTrace();
}
return String.valueOf(result);
}
URL-адрес http://192.168.168.24/WebAvanza/WebAvanzaInterface.asmx
, адрес относится к машине, на которой работает сервер.
Я получаю исключение только после выполнения httpTransport.call
.
Это StackTrace (если это нужно любому)
W/System.err: android.os.NetworkOnMainThreadException
W/System.err: at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1528)
W/System.err: at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:389)
W/System.err: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:230)
W/System.err: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:212)
W/System.err: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:436)
W/System.err: at java.net.Socket.connect(Socket.java:621)
W/System.err: at com.android.okhttp.internal.Platform.connectSocket(Platform.java:145)
W/System.err: at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:141)
W/System.err: at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:112)
W/System.err: at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:184)
W/System.err: at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126)
W/System.err: at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:95)
W/System.err: at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:281)
W/System.err: at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:224)
W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:461)
W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:127)
W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:258)
W/System.err: at org.ksoap2.transport.ServiceConnectionSE.openOutputStream(ServiceConnectionSE.java:130)
W/System.err: at org.ksoap2.transport.HttpTransportSE.sendData(HttpTransportSE.java:295)
W/System.err: at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:184)
W/System.err: at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)
W/System.err: at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113)
W/System.err: at com.infovision.elcam_02.Operations$override.InitTransaction(Operations.java:64)
W/System.err: at com.infovision.elcam_02.Operations$override.InitOperation(Operations.java:40)
W/System.err: at com.infovision.elcam_02.Operations$override.access$dispatch(Unknown Source:49)
W/System.err: at com.infovision.elcam_02.Operations.InitOperation(Unknown Source:15)