Hi I'm developing an app which consume a web service. I can request it correctly in SoapUI, but the same request generated in Android Studio with KSOAP2 Library receives an HTTP Status 400.
The request generated:
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header>
<n0:UserId xmlns:n0="http://www.webservice.com">user</n0:UserId>
<n1:Password xmlns:n1="http://www.webservice.com">pass</n1:Password>
</v:Header>
<v:Body>
<n2:GetAgenciaInfoRequest xmlns:n2="http://www.webservice.com">
<n2:AgencyClientCode>00001</n2:AgencyClientCode>
</n2:GetAgenciaInfoRequest>
</v:Body>
</v:Envelope>
This is my call from WebService.class
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//envelope.dotNet = true;
envelope.implicitTypes = true;
envelope.setAddAdornments(false);
envelope.headerOut = new Element[2];
String UserId = "user";
String Password = "pass";
Element username = new Element().createElement(NAMESPACE, "UserId");
username.addChild(Node.TEXT, UserId);
envelope.headerOut[0] = username;
//h.addChild(Node.ELEMENT, username);
Element pass = new Element().createElement(NAMESPACE, "Password");
pass.addChild(Node.TEXT, Password);
//h.addChild(Node.ELEMENT, pass);
envelope.headerOut[1] = pass;
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
ArrayList<Object> sol = new ArrayList<Object>();
try {
List<HeaderProperty> headerList = new ArrayList<HeaderProperty>();
headerList.add(new HeaderProperty("Content-Type", "application/soap+xml; charset=utf-8"));
ht.debug = true;
ht.call(" http://www.webservice.com/IService1/GetAgenciaInfo", envelope, headerList);
} catch (Exception e) {
Log.d("dump Request: " ,ht.requestDump);
e.printStackTrace();
}
I don't know why is receiving Status 400 when i paste request in SoapUI and works properly and it's difficult to diagnose but any help will be appreciate. The Stack trace only say me the 400 error.
The problem was the URL i tried to user and the content-type.
Note: Try to consume WS in Soap-Ui and copy the URL used in the top of the request window. Maybe it's not necessary the URL finished in ?wsdl.
The content-type appears in the request to, in the RAW tab.