如何使用nodejs将soap complextype发送到axis wsdl服务器

时间:2015-09-17 15:58:14

标签: node.js soap wsdl

我正在使用node作为客户端与java axis wsdl服务进行通信(对此不熟悉)。

有一个node-soap模块可以发送简单类型进行服务。 e.g:

<wsdl:message name="helloArgsRequest">
    <wsdl:part name="str" type="xsd:string"/>
    <wsdl:part name="i" type="xsd:int"/>
</wsdl:message>
<!-- ... -->
<wsdl:operation name="helloArgs" parameterOrder="str i">
    <wsdl:input message="impl:helloArgsRequest" name="helloArgsRequest"/>
    <wsdl:output message="impl:helloArgsResponse" name="helloArgsResponse"/>
</wsdl:operation>

节点:


soap.createClient(url, function(err, client) {

    client.helloArgs({
        str:  "haha",
        i: 100
    }, function(err, result) {
        console.log(result);  // OK
    });


});

但是node-soap不支持complexType(找不到任何关于complexType的示例)。因此,我捕获http请求并获取原始xml数据发布到服务,如下所示:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:impl="http://192.168.0.3:8080/axis/LoginService.jws" xmlns:intf="http://192.168.0.3:8080/axis/LoginService.jws" xmlns:tns1="http://DefaultNamespace">
    <soap:Body>
        <impl:helloArgs>
            <str>haha</str>
            <code>1</code>
        </impl:helloArgs>
    </soap:Body>
</soap:Envelope>

我编写了一个测试方法helloJSON应用了JSONObject的参数类型。更改xml数据如下。不幸的是,它不起作用。

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:impl="http://192.168.0.3:8080/axis/LoginService.jws" xmlns:intf="http://192.168.0.3:8080/axis/LoginService.jws" xmlns:tns1="http://DefaultNamespace">
    <soap:Body>
        <impl:helloJSON>
            <arg type="tns1:JSONResult">
                <code>1</code>
                <data>Hello</data>
                <message>dhad</message>
            </arg>
        </impl:helloJSON>
    </soap:Body>
</soap:Envelope>

服务回复:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
        <soapenv:Fault>
            <faultcode>soapenv:Server.userException</faultcode>
            <faultstring>org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.</faultstring>
            <detail>
                <ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">localhost.localdomain</ns1:hostname>
            </detail>
        </soapenv:Fault>
    </soapenv:Body>
</soapenv:Envelope>

有人可以给我一些原始xml发送complexType数据到轴服务的例子,谢谢。

PS:整个wsdl服务描述

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://192.168.0.3:8080/axis/LoginService.jws" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://192.168.0.3:8080/axis/LoginService.jws" xmlns:intf="http://192.168.0.3:8080/axis/LoginService.jws" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns1="http://DefaultNamespace" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
 <wsdl:types>
  <schema targetNamespace="http://DefaultNamespace" xmlns="http://www.w3.org/2001/XMLSchema">
   <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
   <complexType name="JSONResult">
    <sequence>
     <element name="code" type="xsd:int"/>
     <element name="data" nillable="true" type="xsd:anyType"/>
     <element name="message" nillable="true" type="xsd:string"/>
    </sequence>
   </complexType>
  </schema>
 </wsdl:types>
   <wsdl:message name="helloJSONResponse">
      <wsdl:part name="helloJSONReturn" type="xsd:string"/>
   </wsdl:message>
   <wsdl:message name="helloArgsRequest">
      <wsdl:part name="str" type="xsd:string"/>
      <wsdl:part name="i" type="xsd:int"/>
   </wsdl:message>
   <wsdl:message name="helloArgsResponse">
      <wsdl:part name="helloArgsReturn" type="xsd:string"/>
   </wsdl:message>
   <wsdl:message name="helloJSONRequest">
      <wsdl:part name="arg" type="tns1:JSONResult"/>
   </wsdl:message>
   <wsdl:portType name="LoginService">
      <wsdl:operation name="helloJSON" parameterOrder="arg">
         <wsdl:input message="impl:helloJSONRequest" name="helloJSONRequest"/>
         <wsdl:output message="impl:helloJSONResponse" name="helloJSONResponse"/>
      </wsdl:operation>
      <wsdl:operation name="helloArgs" parameterOrder="str i">
         <wsdl:input message="impl:helloArgsRequest" name="helloArgsRequest"/>
         <wsdl:output message="impl:helloArgsResponse" name="helloArgsResponse"/>
      </wsdl:operation>
   </wsdl:portType>
   <wsdl:binding name="LoginServiceSoapBinding" type="impl:LoginService">
      <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
      <wsdl:operation name="helloJSON">
         <wsdlsoap:operation soapAction=""/>
         <wsdl:input name="helloJSONRequest">
            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://DefaultNamespace" use="encoded"/>
         </wsdl:input>
         <wsdl:output name="helloJSONResponse">
            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://192.168.0.3:8080/axis/LoginService.jws" use="encoded"/>
         </wsdl:output>
      </wsdl:operation>
      <wsdl:operation name="helloArgs">
         <wsdlsoap:operation soapAction=""/>
         <wsdl:input name="helloArgsRequest">
            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://DefaultNamespace" use="encoded"/>
         </wsdl:input>
         <wsdl:output name="helloArgsResponse">
            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://192.168.0.3:8080/axis/LoginService.jws" use="encoded"/>
         </wsdl:output>
      </wsdl:operation>
   </wsdl:binding>
   <wsdl:service name="LoginServiceService">
      <wsdl:port binding="impl:LoginServiceSoapBinding" name="LoginService">
         <wsdlsoap:address location="http://192.168.0.3:8080/axis/LoginService.jws"/>
      </wsdl:port>
   </wsdl:service>
</wsdl:definitions>

0 个答案:

没有答案