Soap Webservice in Node JS - node.js

I am trying to build a soap webservice in node js using the npm module soap. I am using the soap.listen function that is mentioned to launch a soap server in node js. The wsdl file I am including looks like below:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="wscalc1" targetNamespace="http://localhost:8100/api/orderStatusWsdl" xmlns="http://localhost:8100/api/orderStatusWsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<wsdl:message name="receiveOrderStatusRequest">
<wsdl:part name="a" type="xs:string"/>
<wsdl:part name="b" type="xs:string"/>
</wsdl:message>
<wsdl:message name="receiveOrderStatusResponse">
<wsdl:part name="orderStatusResponse" type="xs:string"/>
</wsdl:message>
<wsdl:portType name="orderStatusPort">
<wsdl:operation name="receiveOrderStatus">
<wsdl:input message="receiveOrderStatusRequest"/>
<wsdl:output message="receiveOrderStatusResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="orderStatusBinding" type="orderStatusPort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="receiveOrderStatus">
<soap:operation soapAction="receiveOrderStatus"/>
<wsdl:input>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="orderStatusService">
<wsdl:port binding="orderStatusBinding" name="orderStatus">
<soap:address location="http://localhost:8100/api/orderStatusWsdl"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
The node js code:
var orderStatusWsdlXml = fs.readFileSync(path.join(__dirname, 'soap/wsdl/myWsdl2.wsdl'), 'utf8')
var soapServer = soap.listen(server, BASE_URL + '/orderStatusWsdl', orderStatusSoapService, orderStatusWsdlXml2)
soapServer.log = function(type, data) {
log.d('TYPE: ' + type)
log.d('DATA: ' + JSON.stringify(data, null, 4))
}
After running the node project I try to load the WSDL in SOAP UI client and I get the following error:
Error loading [http://localhost:8100/api/orderStatusWsdl]: org.apache.xmlbeans.XmlException: org.apache.xmlbeans.XmlException: error: Unexpected end of file after null
Where am I going wrong?

Related

How to see ARRAY with NODE JS soap

Hi need to make a WebService with nodejs, this is my first experience to make a SOAP with WSDL.
I use the library "node-wsdl" and i need to stamp a list of array in soap but now i receive a wrong response
I have this response from SOAP:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://localhost:3001/gateway">
<soap:Body>
<tns:listInvoicesResponse>
<tns:0>
<invoice_id>00000</invoice_id>
<ipa_code>00000</ipa_code>
<timing>Thu Jun 04 2015 16:35:46 GMT+0100 (GMT+01:00)</timing>
</tns:0>
<tns:1>
<invoice_id>00001</invoice_id>
<ipa_code>00001</ipa_code>
<timing>Thu Jun 04 2015 16:41:29 GMT+0100 (GMT+01:00)</timing>
</tns:1>
</tns:listInvoicesResponse>
</soap:Body>
</soap:Envelope>
But i need to have a response like this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://localhost:3001/gateway">
<soap:Body>
<tns:listInvoicesResponse>
<lists>
<tns:0>
<invoice_id>00000</invoice_id>
<ipa_code>00000</ipa_code>
<timing>Thu Jun 04 2015 16:35:46 GMT+0100 (GMT+01:00)</timing>
</tns:0>
<tns:1>
<invoice_id>000</invoice_id>
<ipa_code>00001</ipa_code>
<timing>Thu Jun 04 2015 16:41:29 GMT+0100 (GMT+01:00)</timing>
</tns:1>
</lists>
</tns:listInvoicesResponse>
</soap:Body>
</soap:Envelope>
I use this code for retrive info from a DB and print the result on XML like list
var myService = {
ws: {
gateway: {
listInvoices: function(args, callback) {
var ipa_code = args.ipaCode
GetAllInvoice(ipa_code).then(result =>{
console.log(result)
result.map( el =>{
callback(result)
})
})
},
// This is how to define an asynchronous function.
getInvoice: function(args, callback) {
// do some work
}
}
}
};
And my wsdl is this
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="InvoiceGeneral"
targetNamespace="http://localhost:3001/gateway"
xmlns="http://localhost:3001/gateway"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:tns="http://localhost:3001/gateway"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<wsdl:message name="listInvoicesRequest">
<wsdl:part name="ipaCode" type="xs:string"/>
<wsdl:part name="dateFrom" type="xs:string"/>
<wsdl:part name="dateTo" type="xs:string"/>
<wsdl:part name="Accepted_invoice" type="xs:string"/>
</wsdl:message>
<wsdl:message name="getInvoiceRequest">
<wsdl:part name="ipaCode" type="xs:string"/>
<wsdl:part name="refId" type="xs:string"/>
</wsdl:message>
<wsdl:message name="listInvoicesResponse">
<wsdl:part name="InvoiceList" type="tns:string"/>
</wsdl:message>
<wsdl:message name="getInvoiceResponse">
<wsdl:part name="DocInvoice" type="xs:string"/>
<wsdl:part name="descres" type="xs:string"/>
<wsdl:part name="resultCode" type="xs:string"/>
</wsdl:message>
<wsdl:portType name="gatewayP">
<wsdl:operation name="listInvoices">
<wsdl:input message="listInvoicesRequest"/>
<wsdl:output message="listInvoicesResponse"/>
</wsdl:operation>
<wsdl:operation name="getInvoice">
<wsdl:input message="getInvoiceRequest"/>
<wsdl:output message="getInvoiceResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="Gateways" type="gatewayP">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="listInvoices">
<soap:operation soapAction="listInvoices"/>
<wsdl:input><soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal"/></wsdl:input>
<wsdl:output><soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal"/></wsdl:output>
</wsdl:operation>
<wsdl:operation name="getInvoice">
<soap:operation soapAction="getInvoice"/>
<wsdl:input><soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal"/></wsdl:input>
<wsdl:output><soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal"/></wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ws">
<wsdl:port binding="Gateways" name="gateway">
<soap:address location="http://localhost:3001/WebServices/InvoiceGeneral"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

Namespace coming as undefined in the response body for soap in node js.

I am using node js with the soap module 'node-soap' version 0.24.0 (latest).
I am implementing a api framework with the following wsdl file, server.js file. For organisational reasons the wsdl operation is just like a sample template similar to structure of original code.When I make a SOAP request, its being processed successfully but in the response , namespace part in the tags is coming as undefined. This is causing problems to our client who will be making the api calls, they are not able to read the response properly.
I am unable to find a fix for this and do not know if I shoukld change something in the wsdl file or the server.js.
wscalc1.wsdl
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="wscalc1" targetNamespace="http://localhost:8000/wscalc1"
xmlns="http://localhost:8000/wscalc1"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<wsdl:message name="multiplicarRequest">
<wsdl:part name="a" type="xs:string"/>
<wsdl:part name="b" type="xs:string"/>
</wsdl:message>
<wsdl:message name="multiplicarResponse">
<wsdl:part name="mulres" type="xs:string"/>
</wsdl:message>
<wsdl:portType name="calcP">
<wsdl:operation name="multiplicar">
<wsdl:input message="multiplicarRequest"/>
<wsdl:output message="multiplicarResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="calcB" type="calcP">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="multiplicar">
<soap:operation soapAction="multiplicar"/>
<wsdl:input>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ws">
<wsdl:port binding="calcB" name="calc">
<soap:address location="http://localhost:8001/wscalc1"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
server.js
"use strict";
var soap = require('soap');
var http = require('http');
var service = {
ws: {
calc: {
multiplicar : function(args) {
var n = args.a * args.b;
return { mulres : n };
}
}
}
};
var xml = require('fs').readFileSync('wscalc1.wsdl', 'utf8');
var server = http.createServer(function(request,response) {
response.end("404: Not Found: "+request.url);
});
server.listen(8001);
soap.listen(server, '/wscalc1', service, xml);
post request
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsc="http://localhost:8000/wscalc1">
<soapenv:Header/>
<soapenv:Body>
<wsc:multiplicar>
<a>2</a>
<b>3</b>
</wsc:multiplicar>
</soapenv:Body>
</soapenv:Envelope>
response
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" >
<soap:Body>
<undefined:multiplicarResponse>
<undefined:mulres>6</undefined:mulres>
</undefined:multiplicarResponse>
</soap:Body>
</soap:Envelope>
I had the same issue. I'm not sure how to apply my solution to your code, but the idea is that you need to specify your namespace in <definitions> tag and assign a prefix for it, like:
<definitions
name="ININWebService"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="WebServices.TVTraffic"
targetNamespace="WebServices.TVTraffic"
>
Then I used the same prefix 'tns' to define my messages and elements, like element="tns:updatePayment" instead of element="updatePayment" and so on, and finally I've got working namespace prefixes.
Hope it helps.
I have been able to make it work, but I had to do some changes to the wsdl, I also used Eclipse wsdl editor to verify if there are any error. Please find the details below:
wscalc1.wsdl
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://localhost:8000/wscalc1" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="wscalc1" targetNamespace="http://localhost:8000/wscalc1">
<wsdl:message name="sumarRequest">
<wsdl:part name="a" type="xsd:string"></wsdl:part>
<wsdl:part name="b" type="xsd:string"></wsdl:part>
</wsdl:message>
<wsdl:message name="sumarResponse">
<wsdl:part name="sumres" type="xsd:string"/>
</wsdl:message>
<wsdl:message name="multiplicarRequest">
<wsdl:part name="a" type="xsd:string"></wsdl:part>
<wsdl:part name="b" type="xsd:string"></wsdl:part>
</wsdl:message>
<wsdl:message name="multiplicarResponse">
<wsdl:part name="mulres" type="xsd:string"></wsdl:part>
</wsdl:message>
<wsdl:portType name="calcP">
<wsdl:operation name="sumar">
<wsdl:input message="tns:sumarRequest"></wsdl:input>
<wsdl:output message="tns:sumarResponse"/>
</wsdl:operation>
<wsdl:operation name="multiplicar">
<wsdl:input message="tns:multiplicarRequest"></wsdl:input>
<wsdl:output message="tns:multiplicarResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="calcB" type="tns:calcP">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="sumar">
<soap:operation soapAction="sumar" style="rpc"/>
<wsdl:input>
<soap:body namespace="http://localhost:8000/wscalc1" use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body namespace="http://localhost:8000/wscalc1" use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="multiplicar">
<soap:operation soapAction="multiplicar" style="rpc"/>
<wsdl:input>
<soap:body namespace="http://localhost:8000/wscalc1" use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body namespace="http://localhost:8000/wscalc1" use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ws">
<wsdl:port binding="tns:calcB" name="calc">
<soap:address location="http://localhost:8001/wscalc1"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
server.js
const soap = require('soap');
const http = require('http');
const service = {
ws: {
calc: {
sumar : function(args) {
var n = 1*args.a + 1*args.b;
return { sumres : n };
},
multiplicar : function(args) {
var n = args.a * args.b;
return { mulres : n };
}
}
}
};
const xml = require('fs').readFileSync('wscalc1.wsdl', 'utf8');
const server = http.createServer(function(request,response) {
response.end("404: Not Found: "+request.url);
});
server.listen(8001);
soap.listen(server, '/wscalc1', service, xml);
soap request
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsc="http://localhost:8000/wscalc1">
<soapenv:Header/>
<soapenv:Body>
<wsc:sumar>
<a>2</a>
<b>3</b>
</wsc:sumar>
</soapenv:Body>
</soapenv:Envelope>
response
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://localhost:8000/wscalc1">
<soap:Body>
<tns:sumarResponse>
<tns:sumres>5</tns:sumres>
</tns:sumarResponse>
</soap:Body>
</soap:Envelope>

how to use nodejs send soap complextype to axis wsdl server

I'm using node as client communicate with java axis wsdl service (not familiar to this).
There is a node-soap module could send simple types to service. 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>
node:
soap.createClient(url, function(err, client) {
client.helloArgs({
str: "haha",
i: 100
}, function(err, result) {
console.log(result); // OK
});
});
But node-soap does not support complexType (Cannot find any example about complexType). So I capture the http request and get raw xml data post to service, as follow:
<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>
I write a test method helloJSON apply an argument typeof JSONObject. Change the xml data as follow. Unlucky, it not work.
<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>
The service response:
<?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>
Could somebody give me some example of the raw xml send complexType data to axis service, thanks.
PS: the whole wsdl service description
<?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>

Simple webservice with node-soap

I am trying to implement a simple web service using SOAP using Node Js and node-soap, but the client side seems to have problems using the server.
assert.js:92
throw new assert.AssertionError({
^
AssertionError: invalid message definition for document style binding
My wsdl file is:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="wscalc1"
targetNamespace="http://localhost:8000/wscalc1"
xmlns="http://localhost:8000/wscalc1"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<wsdl:message name="sumarRequest">
<wsdl:part name="a" type="xs:string"></wsdl:part>
<wsdl:part name="b" type="xs:string"></wsdl:part>
</wsdl:message>
<wsdl:message name="multiplicarRequest">
<wsdl:part name="a" type="xs:string"></wsdl:part>
<wsdl:part name="b" type="xs:string"></wsdl:part>
</wsdl:message>
<wsdl:message name="multiplicarResponse">
<wsdl:part name="res" type="xs:string"></wsdl:part>
</wsdl:message>
<wsdl:message name="sumarResponse">
<wsdl:part name="res" type="xs:string"></wsdl:part>
</wsdl:message>
<wsdl:portType name="calcP">
<wsdl:operation name="sumar">
<wsdl:input message="sumarRequest"></wsdl:input>
<wsdl:output message="sumarResponse"></wsdl:output>
</wsdl:operation>
<wsdl:operation name="multiplicar">
<wsdl:input message="multiplicarRequest"></wsdl:input>
<wsdl:output message="multiplicarResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="calcB" type="calcP">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="sumar">
<soap:operation soapAction="sumar"/>
<wsdl:input>
<soap:body use="literal"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="multiplicar">
<soap:operation soapAction="multiplicar"/>
<wsdl:input>
<soap:body use="literal"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ws">
<wsdl:port name="calc" binding="calcB">
<soap:address location="http://localhost:8000/wscalc1"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
server.js
var soap = require('soap');
var http = require('http');
var service = {
ws: {
calc: {
sumar : function(args) {
var n = args.a + args.b;
return { res : n };
},
multiplicar : function(args) {
var n = args.a * args.b;
return { res : n }
}
}
}
}
var xml = require('fs').readFileSync('wscalc1.wsdl', 'utf8'),
server = http.createServer(function(request,response) {
response.end("404: Not Found: "+request.url)
});
server.listen(8000);
soap.listen(server, '/wscalc1', service, xml);
client.js
var soap = require('soap');
var url = 'http://localhost:8000/wscalc1?wsdl';
soap.createClient(url, function(err, client) {
if (err) throw err;
console.log(client.describe().ws.calc);
client.multiplicar({"a":"1","b":"2"},function(err,res){
if (err) throw err;
console.log(res);
});
});
with that code the output is:
{ sumar:
{ input: { a1: 'Request', b1: 'Request' },
output: { res: 'Response' } },
multiplicar:
{ input: { a2: 'Request', b2: 'Request' },
output: { res: 'Response' } } }
assert.js:92
throw new assert.AssertionError({
^
AssertionError: invalid message definition for document style binding
any help will be really appreciated
As user672320 pointed out the reason client.js failed was because the format of the wsdl used was 'RPC/literal' but the style was set as 'document' rather than RPC.
In fact any one of five formats can be used for wsdl, each has a diferent format.
See Which style of WSDL should I use? for a discussion of which style to use.
Also, the example given is not complete.
See below for expanded version:
wsdl file:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="wscalc1" targetNamespace="http://localhost:8000/wscalc1" xmlns="http://localhost:8000/wscalc1" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<wsdl:message name="sumarRequest">
<wsdl:part name="a" type="xs:string"/>
<wsdl:part name="b" type="xs:string"/>
</wsdl:message>
<wsdl:message name="multiplicarRequest">
<wsdl:part name="a" type="xs:string"/>
<wsdl:part name="b" type="xs:string"/>
</wsdl:message>
<wsdl:message name="multiplicarResponse">
<wsdl:part name="mulres" type="xs:string"/>
</wsdl:message>
<wsdl:message name="sumarResponse">
<wsdl:part name="sumres" type="xs:string"/>
</wsdl:message>
<wsdl:portType name="calcP">
<wsdl:operation name="sumar">
<wsdl:input message="sumarRequest"/>
<wsdl:output message="sumarResponse"/>
</wsdl:operation>
<wsdl:operation name="multiplicar">
<wsdl:input message="multiplicarRequest"/>
<wsdl:output message="multiplicarResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="calcB" type="calcP">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="sumar">
<soap:operation soapAction="sumar"/>
<wsdl:input>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="multiplicar">
<soap:operation soapAction="multiplicar"/>
<wsdl:input>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ws">
<wsdl:port binding="calcB" name="calc">
<soap:address location="http://localhost:8001/wscalc1"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
server.js:
/*jslint node: true */
"use strict";
var soap = require('soap');
var http = require('http');
var service = {
ws: {
calc: {
sumar : function(args) {
var n = 1*args.a + 1*args.b;
return { sumres : n };
},
multiplicar : function(args) {
var n = args.a * args.b;
return { mulres : n };
}
}
}
};
var xml = require('fs').readFileSync('wscalc1.wsdl', 'utf8');
var server = http.createServer(function(request,response) {
response.end("404: Not Found: "+request.url);
});
server.listen(8001);
soap.listen(server, '/wscalc1', service, xml);
client.js:
var soap = require('soap');
var url = 'http://localhost:8001/wscalc1?wsdl';
soap.createClient(url, function(err, client) {
if (err) throw err;
console.log(client.describe().ws.calc);
client.multiplicar({a: 4,b: 3},function(err,res){
if (err) throw err;
console.log(res);
});
client.sumar({a: 4,b: 3},function(err,res){
if (err) throw err;
console.log(res);
});
});
with that the code output is:
{ sumar:
{ input: { a: 'xs:string', b: 'xs:string' },
output: { sumres: 'xs:string' } },
multiplicar:
{ input: { a: 'xs:string', b: 'xs:string' },
output: { mulres: 'xs:string' } } }
{ mulres: '12' }
{ sumres: '7' }
in the wsdl file what i change is the style from document to rpc trying to get antoher response using the client.js
What i receive is this output.
{ sumar:
{ input: { a: 'xs:string', b: 'xs:string' },
output: { res: 'xs:string' } },
multiplicar:
{ input: { a: 'xs:string', b: 'xs:string' },
output: { res: 'xs:string' } } }
{ res: '2' }

WSO2 BPS: How to pass Header values as a part of a Message in BPEL Invoke

My web service operation is defined like below. Where I have a header parameter as well.
public void method(#WebParam(name="OrderNo", mode=WebParam.Mode.IN) String order_no_,
#WebParam(name="user", mode=WebParam.Mode.IN, header=true) String user)
Now when I deploy this service I get a WSDL which looks like this.
<?xml version="1.0" ?>
<wsdl:definitions ... >
<wsdl:types>
</xs:schema>
...
<xs:element name="method" type="tns:method"></xs:element>
<xs:complexType name="method">
<xs:sequence>
<xs:element minOccurs="0" name="OrderNo" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
...
<xs:element name="user" nillable="true" type="xs:string"></xs:element>
...
</xs:schema>
</wsdl:types>
...
<wsdl:message name="method">
<wsdl:part element="tns:method" name="parameters" />
<wsdl:part element="tns:user" name="user" />
</wsdl:message>
...
<wsdl:portType name="CustomerOrderService">
<wsdl:operation name="method">
<wsdl:input message="tns:method" name="method" />
<wsdl:output ... />
<wsdl:fault ... />
</wsdl:operation>
</wsdl:portType>
...
<wsdl:binding name="OrderSoapBinding" type="tns:OrderService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="method">
<soap:operation soapAction="" style="document" />
<wsdl:input name="method">
<soap:header message="tns:method" part="user" use="literal" />
<soap:body parts="parameters" use="literal" />
</wsdl:input>
<wsdl:output name="...">
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="...">
...
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
</wsdl:definitions>
As you can see the header is part of the message used as input for the service request. Hwen I use soap UI to test this WSDL it generated a proper soap message with the "user" property as part of the header.
When I use this service as a partner link in a Carbon BPEL process, and assign a value to the "user" part in the invoke message, the value is not included in the header.
<bpel:variable name="method_Input" messageType="ns0:method" />
<bpel:assign name="...">
...
<bpel:copy>
<bpel:from>$input.payload/tns:TaskReceiver</bpel:from>
<bpel:to>$method_Input.user</bpel:to>
</bpel:copy>
</bpel:assign>
You can see that the message part is assigned the proper value,
The problem is this message part which is bound to the header of of the soap message is never included in the soap header.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<method xmlns="http://customerorder.service.test/">
<OrderNo xmlns="">ORD00011</OrderNo>
</method>
</soapenv:Body>
</soapenv:Envelope>
Thanks in advance to any help provided.

Resources