I have a wsdl and xsd files and want to create SOAP request to web server on python. I have never worked with soap before so my question probably simple but I spend the four hours and havn’t found the solution.
I try two ways: low level request and KSOAP2 on Android.
wsdl
<wsdl:message name="<some request>">
<wsdl:part element="txh:<some request>" name="parameters"/>
</wsdl:message>
<wsdl:message name="<some response>">
<wsdl:part element="txh:<some response>" name="parameters"/>
</wsdl:message>
xsd
<xs:element name=""<some request>">
<xs:annotation>
<xs:documentation>"<text>"</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="mode" type="response-mode"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="<some response>">
<xs:complexType>
<xs:annotation>
<xs:documentation>"<text>"</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element ref="<text>"/>
<xs:element name="<another text>" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="<name a>" type="xs:int"/>
<xs:element name="<name b>" type="xs:int"/>
<xs:element name="<name c>" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
Code in Android:
private final static String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<SOAP-ENV:Envelope " +
"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
"xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
"<SOAP-ENV:Header>" +
"</SOAP-ENV:Header>" +
"<SOAP-ENV:Body xmlns:ns1=\"<namespace>\">" +
" <xs:element name=\"<request>\"> " +
"<xs:annotation>" +
"<xs:documentation>"<text>"</xs:documentation>" +
"</xs:annotation>" +
"<xs:complexType>" +
"<xs:sequence>" +
"<xs:element name=\""<text>"\" type=\"response-mode\"/>" +
"</xs:sequence>" +
"</xs:complexType>" +
"</xs:element>" +
"</SOAP-ENV:Body>" +
"</SOAP-ENV:Envelope>";
public Entity execute(final String body) {
Log.d(TAG, "Start request ");
Entity result = new Entity();
AndroidHttpClient client = AndroidHttpClient.newInstance(TAG);
HttpParams params = client.getParams();
HttpConnectionParams.setConnectionTimeout(params, 10000);
HttpConnectionParams.setSoTimeout(params, 15000);
HttpProtocolParams.setUseExpectContinue(params, true);
HttpPost post = new HttpPost(url);
post.setParams(params);
post.setHeader("soapaction", NAMESPACE.concat("/").concat(METHOD));
post.setHeader("Content-Type", "text/xml; charset-utf8");
try {
String request = createRequest(xml);
HttpEntity entityToRequest = new StringEntity(request);
post.setEntity(entityToRequest);
Log.d(TAG, post.toString());
HttpResponse response = client.execute(post);
final int status = response.getStatusLine().getStatusCode();
if (HttpStatus.SC_OK == status) {
HttpEntity entity = response.getEntity();
String str = EntityUtils.toString(entity);
Log.d(TAG, str);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
On this request I get a 500 server code, so I suppose that the issue in my request. Do you think that it is formed well?
I have found the solution. The soupUI and similar instruments can help to understand a structure of your soap rtequests.