0

我有一个 wsdl 和 xsd 文件,想在 python 上创建对 Web 服务器的 SOAP 请求。我以前从未使用过肥皂,所以我的问题可能很简单,但我花了四个小时并没有找到解决方案。

我尝试了两种方法:Android 上的低级请求和 KSOAP2。

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>

安卓中的代码:

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();
    }

在这个请求中,我得到了一个 500 服务器代码,所以我认为是我的请求中的问题。你觉得它形成的好吗?

4

1 回答 1

0

我找到了解决方案。soupUI 和类似的工具可以帮助理解你的soap 请求的结构。

于 2012-08-16T09:54:18.817 回答