I'm having problem when trying to call SOAP service from android. I google and I find out that i should be using ksoap2. So i installed that library and get some code...
String METHOD_NAME = "name";
String SOAP_ACTION = "url/name";
String NAMESPACE = "url";
String URL = "url";
//you can get these values from the wsdl file^
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); //set up request
request.addProperty("user", "user");
request.addProperty("pass", "pass");
//variable name, value. I got the variable name, from the wsdl file!
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); //put all required data into a soap envelope
envelope.setOutputSoapObject(request); //prepare request
List<HeaderProperty> headerList = new ArrayList<HeaderProperty>();
headerList.add(new HeaderProperty("Content-Type", "text/xml; charset=utf-8"));
headerList.add(new HeaderProperty("SoapAction", "url/name"));
HttpTransportSE httpTransport = new HttpTransportSE(URL);
httpTransport.debug = true;
try {
httpTransport.call(SOAP_ACTION, envelope, headerList);
SoapObject result=(SoapObject)envelope.getResponse();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (XmlPullParserException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
and it throws an exception in XmlPullParserException e2 called:
org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <html>@2:7 in java.io.InputStreamReader@406da6b8)
So now i have no idea how to make it work. I think android has that really poorly managed because on iphone i get it to work in the matter of minutes.
Btw if it might help that's the envelope that should be used:
<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tns=\"url\" " +
"xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" " +
"xmlns:soap-enc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" >" +
"<SOAP-ENV:Body><mns:name xmlns:mns=\"url\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" +
"<user xsi:type=\"xsd:string\">user</user>" +
"<pass xsi:type=\"xsd:string\">pass</pass>" +
"</mns:name></SOAP-ENV:Body></SOAP-ENV:Envelope>
Any helkp would be appriciated because i'm trying to get this to work for quite some time now...
maybe that helps the expected result is like followed:
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:MPListResponse><return xsi:type="xsd:string">[{"tip":"123456","stevilka":"123456789","key":"some value","zacetek":"01.05.2007","potek":"01.01.2018","axa":0},]</return></ns1:MPListResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
that's my httptransport request:
Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://www.w3.org/2003/05/soap-encoding" xmlns:v="http://www.w3.org/2003/05/soap-envelope"><v:Header /><v:Body><n0:name id="o0" c:root="1" xmlns:n0="url"><user i:type="d:string">user</user><pass i:type="d:string">pass</pass></n0:MPList></v:Body></v:Envelope>
wsdl2ksoap may help you here, followed by the use of the java SAXparser if your xml responses are not too long. At least that's the approach I have taken with success.