Hi, I'm kind of new to Android development, and i'm having some trouble with some code. I'm trying to reach some webservices using ksoap2 but the Call method is giving me some headaches..
Here's the code I'm using.
androidHttpTransport.call throws an exception with empty Message. I can't understand why.
Also i added to the Manifest
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
If needed, I will provide public IP address for testing purposes by private message.
XML
Here's the code I'm using.
Code:
import org.ksoap2.*;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.Marshal;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
(...)
private static final String NAMESPACE = "http://192.168.10.1:9998/";
private static final String URL = "http://192.168.10.1:9998/updatetabelas.asmx";
private static final String GET_INTREBARE = "HelloWorld";
private void msgbox(String __title, String __message){
AlertDialog.Builder __msg=new AlertDialog.Builder(BaseDadosActivity.this);
__msg.setTitle(__title);
__msg.setMessage(__message);
__msg.setNeutralButton("Ok", null);
__msg.show();
}
public void callHello()
{
try {
SoapSerializationEnvelope env = new SoapSerializationEnvelope(
SoapEnvelope.VER12);
env.dotNet = true;
env.xsd = SoapSerializationEnvelope.XSD;
env.enc = SoapSerializationEnvelope.ENC;
SoapObject request = new SoapObject(NAMESPACE, "HelloWorld");
env.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call("", env);
SoapObject result = (SoapObject) env.getResponse();
msgbox("Result", result.toString());
} catch (Exception e) {
e.getStackTrace();
}
}
Also i added to the Manifest
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
If needed, I will provide public IP address for testing purposes by private message.
XML
Code:
SOAP 1.1
POST /updatetabelas.asmx HTTP/1.1
Host: 192.168.10.1
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://192.168.10.1:9998/HelloWorld"
<?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>
<HelloWorld xmlns="http://192.168.10.1:9998/" />
</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>
<HelloWorldResponse xmlns="http://192.168.10.1:9998/">
<HelloWorldResult>string</HelloWorldResult>
</HelloWorldResponse>
</soap:Body>
</soap:Envelope>
SOAP 1.2
Segue-se um exemplo de pedido e resposta SOAP 1.2. É necessário substituir os marcadores de posição mostrados por valores reais.
POST /updatetabelas.asmx HTTP/1.1
Host: 192.168.10.1
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>
<HelloWorld xmlns="http://192.168.10.1:9998/" />
</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>
<HelloWorldResponse xmlns="http://192.168.10.1:9998/">
<HelloWorldResult>string</HelloWorldResult>
</HelloWorldResponse>
</soap12:Body>
</soap12:Envelope>