2018 SOAP(3)SOAP with NodeJS node-soap
Directly Use SOAP Package
https://github.com/vpulim/node-soap#basicauthsecurity
https://stackoverflow.com/questions/22884513/simple-webservice-with-node-soap
Change the dependency to use node-soap there, other settings are the same as before in package.json
"dependencies": {
"@types/autobahn": "^0.9.37",
"@types/chai": "^4.0.4",
"@types/mocha": "^2.2.43",
"@types/node": "^8.0.28",
"@types/sinon": "^2.3.5",
"autobahn": "^0.12.0",
"aws-sdk": "^2.103.0",
"base-64": "^0.1.0",
"chai": "^4.1.2",
"config": "^1.26.2",
"dynamodb-local": "0.0.18",
"log4js": "^2.3.3",
"redis": "^2.8.0",
"request": "^2.73.0",
"request-promise": "^4.1.1",
"sinon": "^3.2.1",
"sinon-test": "^2.1.1",
"typescript": "^2.1.4",
"uuid-validate": "0.0.2",
"express": "4.16.3",
"soap": "0.23.0"
}
The WSDL file we download from the previous example from URL http://localhost:3000/calculatorService?wsdl is as follow calculatorService.wsdl
<?xml version='1.0'encoding='UTF-8'?>
<wsdl:definitions xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/' name='CalculatorService' targetNamespace='http://localhost:3000' xmlns:tns='http://localhost:3000'>
<wsdl:types>
<xsd:schema attributeFormDefault='unqualified' elementFormDefault='unqualified' xmlns:xsd='http://www.w3.org/2001/XMLSchema' targetNamespace='http://localhost:3000'>
<xsd:element name='add' type='tns:CalculatorInput'/>
<xsd:element name='CalculatorResult' type='tns:CalculatorResult'/>
<xsd:element name='subtract'type='tns:CalculatorInput'/>
<xsd:complexType name='CalculatorInput'>
<xsd:sequence>
<xsd:element name='a' type='xsd:int'/>
<xsd:element name='b' type='xsd:int'/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name='CalculatorResult'>
<xsd:sequence>
<xsd:element name='value' type='xsd:int'/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name='addMessage'>
<wsdl:part name='add'element='tns:add'/>
</wsdl:message>
<wsdl:message name='CalculatorResultMessage'>
<wsdl:part name='CalculatorResult' element='tns:CalculatorResult'/>
</wsdl:message>
<wsdl:message name='subtractMessage'>
<wsdl:part name='subtract' element='tns:subtract'/>
</wsdl:message>
<wsdl:portType name='CalculatorPortType'>
<wsdl:operation name='add'>
<wsdl:input message='tns:addMessage'/>
<wsdl:output message='tns:CalculatorResultMessage'/>
</wsdl:operation>
<wsdl:operation name='subtract'>
<wsdl:input message='tns:subtractMessage'/>
<wsdl:output message='tns:CalculatorResultMessage'/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name='CalculatorServiceBinding' type='tns:CalculatorPortType'>
<soap:binding style='document' transport='http://schemas.xmlsoap.org/soap/http'/>
<wsdl:operation name='add'>
<wsdl:input>
<soap:body use='literal' parts='add'/>
</wsdl:input>
<wsdl:output>
<soap:body use='literal' parts='CalculatorResult'/>
</wsdl:output>
<soap:operation soapAction='add'/>
</wsdl:operation>
<wsdl:operation name='subtract'>
<wsdl:input>
<soap:body use='literal' parts='subtract'/>
</wsdl:input>
<wsdl:output>
<soap:body use='literal' parts='CalculatorResult'/>
</wsdl:output>
<soap:operation soapAction='subtract'/>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name='CalculatorService'>
<wsdl:port name='CalculatorPort' binding='tns:CalculatorServiceBinding'>
<soap:address location='http://localhost:3000'/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Directly Implement the soap.ts as follow:
import * as express from 'express';
import * as http from 'http';
let soap = require('soap');
export class SoapServer {
private server;
constructor(listenPort: number, address: string) {
}
public async init() {
}
public async start() {
let soapService = {
CalculatorService: {
CalculatorPort: {
add: function(args) {
let n = args.a + args.b;
return { value: n };
},
subtract: function(args) {
let n = args.a - args.b;
return { value: n };
}
}
}
};
let app = express();
let xml = require('fs').readFileSync('/Users/hluo/company/code/services.soapexport.auth/wsdl/calculatorService.wsdl', 'utf8');
app.listen(3000, function(){
soap.listen(app, '/calculatorService', soapService, xml);
});
}
}
References:
https://github.com/vpulim/node-soap#basicauthsecurity
https://stackoverflow.com/questions/22884513/simple-webservice-with-node-soap
http://sillycat.iteye.com/blog/2414631
2018 SOAP(3)SOAP with NodeJS node-soap
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326125317&siteId=291194637
Recommended
Ranking