diff --git a/soap/soap-tests.ts b/soap/soap-tests.ts index 5229cfcf8e..8010d7285e 100644 --- a/soap/soap-tests.ts +++ b/soap/soap-tests.ts @@ -2,6 +2,8 @@ import * as soap from 'soap'; import * as events from 'events'; +import * as fs from "fs"; +import * as http from "http"; const url = 'http://example.com/wsdl?wsdl'; const wsdlOptions = { name: 'value' }; @@ -21,3 +23,45 @@ soap.createClient(url, wsdlOptions, function(err: any, client: soap.Client) { }); }); +var myService = { + MyService: { + MyPort: { + MyFunction: function(args: any) { + return { + name: args.name + }; + }, + + // This is how to define an asynchronous function. + MyAsyncFunction: function(args: any, callback: any) { + // do some work + callback({ + name: args.name + }); + }, + + // This is how to receive incoming headers + HeadersAwareFunction: function(args: any, cb: any, headers: any) { + return { + name: headers.Token + }; + }, + + // You can also inspect the original `req` + reallyDeatailedFunction: function(args: any, cb: any, headers: any, req: any) { + console.log('SOAP `reallyDeatailedFunction` request from ' + req.connection.remoteAddress); + return { + name: headers.Token + }; + } + } + } + }; + +var xml = fs.readFileSync('myservice.wsdl', 'utf8'), + server = http.createServer(function(request,response) { + response.end("404: Not Found: " + request.url); + }); + +server.listen(8000); +soap.listen(server, '/wsdl', myService, xml); diff --git a/soap/soap.d.ts b/soap/soap.d.ts index 21fcb98514..fa26cbf04c 100644 --- a/soap/soap.d.ts +++ b/soap/soap.d.ts @@ -1,9 +1,9 @@ // Type definitions for soap // Project: https://www.npmjs.com/package/soap -// Definitions by: Nicole Wang +// Definitions by: Nicole Wang , Cage Fox // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// +/// declare module 'soap' { import * as events from 'events'; @@ -18,4 +18,12 @@ declare module 'soap' { } function createClient(wsdlPath: string, options: any, fn: (err: any, client: Client) => void): void; -} \ No newline at end of file + export interface Server extends events.EventEmitter { + addSoapHeader(soapHeader: any, name:any, namespace: any, xmlns: any): any; + changeSoapHeader(index: any, soapHeader: any, name: any, namespace: any, xmlns: any): any; + getSoapHeaders(): any; + clearSoapHeaders(): any; + log(type: any, data: any): any; + } + export function listen(server: any, path: string, service:any, wsdl: string): Server; +}