https://github.com/robinbuschmann/soap-typescript
SOAP decorators for creating wsdl's and annotating services to provide metadata for node-soap
https://github.com/robinbuschmann/soap-typescript
annotations decorators schema soap
Last synced: about 1 year ago
JSON representation
SOAP decorators for creating wsdl's and annotating services to provide metadata for node-soap
- Host: GitHub
- URL: https://github.com/robinbuschmann/soap-typescript
- Owner: RobinBuschmann
- Created: 2016-12-06T09:03:53.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-04-22T20:20:01.000Z (about 8 years ago)
- Last Synced: 2025-03-27T15:52:34.802Z (about 1 year ago)
- Topics: annotations, decorators, schema, soap
- Language: TypeScript
- Homepage:
- Size: 176 KB
- Stars: 19
- Watchers: 1
- Forks: 2
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://travis-ci.org/RobinBuschmann/soap-typescript)
# soap-decorators
SOAP decorators for creating wsdl's and annotating services to provide metadata for [node-soap](https://github.com/vpulim/node-soap).
## Installation
```
npm install soap-decorators --save
```
## Usage
### Input and output messages
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](https://github.com/RobinBuschmann/xsd-decorators).
### Soap service and operations
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
});
}
}
```
### Use soap service with express.js
*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));
```
### Requesting WSDL
Now you can ask for the **wsdl** by requesting against the defined
endpoint.
```
GET /soap/calculation?wsdl
```
*Response*
```xml
```
### Using operations
```xml
POST /soap/calculation
3
1
```
```xml
POST /soap/calculation
8
4
```
*Response*
```xml
4
```
### Retrieving WSDL from class or instance
```typescript
import {createWsdl} from 'soap-decorators';
const instance = new CalculatorController();
createWsdl(instance) === createWsdl(CalculatorController);
```