如何使用nodejs发送soap复杂types到axis wsdl服务器

我使用节点作为客户端与java轴wsdl服务进行通信(不熟悉这一点)。

有一个node-soap模块可以发送简单types的服务。 例如:

<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> 

我写了一个testing方法helloJSON应用JSONObject的参数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>