SOAP decorators for creating wsdl's and annotating services to provide metadata for node-soap
npm install soap-decorators
npm install soap-decorators --save
`Usage
$3
Define input and output message interfaces for a soap service.
`typescript
import {XSDComplexType, XSDElement} from 'soap-decorators';@XSDComplexType
export class CalculatorInput {
@XSDElement
a: number;
@XSDElement
b: number;
}
@XSDComplexType
export class CalculatorResult {
@XSDElement
value: number;
}
`
For a more advanced usage of creating xsd schemas with decorators
see xsd-decorators.$3
Define soap service, its operations and specify input and output
messages via the previously defined classes.
`typescript
import {SoapService, SoapOperation} from 'soap-decorators';@SoapService({
portName: 'CalculatorPort',
serviceName: 'CalculatorService'
})
export class CalculatorController {
@SoapOperation(CalculatorResult)
add(data: CalculatorInput) {
return {
value: data.a + data.b
};
}
@SoapOperation(CalculatorResult)
subtract(data: CalculatorInput) {
return Promise.resolve({
value: data.a - data.b
});
}
}
`$3
soap-decorators provides a middleware for express, which does
all the magic for you. The wsdl will be resolved and the location
address and tns will be set automatically.
`typescript
import {soap} from 'soap-decorators';const app = express();
const calculatorController = new CalculatorController();
// resolves wsdl for you and sets location address and tns to current requested url
app.use('/soap/calculation', soap(calculatorController));
`$3
Now you can ask for the wsdl by requesting against the defined
endpoint.
`
GET /soap/calculation?wsdl
`
Response
`xml
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
name='CalculatorService'
targetNamespace='https://calculation.example.com'
xmlns:tns='https://calculation.example.com'>
`
$3
`xml
POST /soap/calculation
3
1
`
`xml
POST /soap/calculation
8
4
`
Response
`xml
4
`
$3
`typescript
import {createWsdl} from 'soap-decorators';const instance = new CalculatorController();
createWsdl(instance) === createWsdl(CalculatorController);
``