@@ -64,6 +64,7 @@ export interface Server {
64
64
interface IExecuteMethodOptions {
65
65
serviceName ?: string ;
66
66
portName ?: string ;
67
+ soapAction ?: string ;
67
68
methodName ?: string ;
68
69
outputName ?: string ;
69
70
args ?: any ;
@@ -283,6 +284,13 @@ export class Server extends EventEmitter {
283
284
}
284
285
}
285
286
287
+ private _getSoapAction ( req : Request ) {
288
+ const soapAction : string = req . headers [ 'soapaction' ] as string ;
289
+ return ( soapAction . indexOf ( '"' ) === 0 )
290
+ ? soapAction . slice ( 1 , - 1 )
291
+ : soapAction ;
292
+ }
293
+
286
294
private _process ( input , req : Request , res : Response , cb : ( result : any , statusCode ?: number ) => any ) {
287
295
const pathname = url . parse ( req . url ) . pathname . replace ( / \/ $ / , '' ) ;
288
296
const obj = this . wsdl . xmlToObject ( input ) ;
@@ -360,6 +368,7 @@ export class Server extends EventEmitter {
360
368
this . _executeMethod ( {
361
369
serviceName : serviceName ,
362
370
portName : portName ,
371
+ soapAction : this . _getSoapAction ( req ) ,
363
372
methodName : methodName ,
364
373
outputName : methodName + 'Response' ,
365
374
args : body [ methodName ] ,
@@ -380,6 +389,7 @@ export class Server extends EventEmitter {
380
389
this . _executeMethod ( {
381
390
serviceName : serviceName ,
382
391
portName : portName ,
392
+ soapAction : this . _getSoapAction ( req ) ,
383
393
methodName : pair . methodName ,
384
394
outputName : pair . outputName ,
385
395
args : body [ messageElemName ] ,
@@ -464,6 +474,13 @@ export class Server extends EventEmitter {
464
474
}
465
475
}
466
476
477
+ private _getMethodNameBySoapAction ( binding : BindingElement , soapAction : string ) {
478
+ for ( const methodName in binding . methods ) {
479
+ if ( binding . methods [ methodName ] . soapAction === soapAction )
480
+ return methodName ;
481
+ }
482
+ }
483
+
467
484
private _executeMethod (
468
485
options : IExecuteMethodOptions ,
469
486
req : Request ,
@@ -477,7 +494,10 @@ export class Server extends EventEmitter {
477
494
let headers ;
478
495
const serviceName = options . serviceName ;
479
496
const portName = options . portName ;
480
- const methodName = options . methodName ;
497
+ const binding = this . wsdl . definitions . services [ serviceName ] . ports [ portName ] . binding ;
498
+ const methodName = options . soapAction
499
+ ? this . _getMethodNameBySoapAction ( binding , options . soapAction )
500
+ : options . methodName ;
481
501
const outputName = options . outputName ;
482
502
const args = options . args ;
483
503
const style = options . style ;
@@ -523,13 +543,13 @@ export class Server extends EventEmitter {
523
543
if ( style === 'rpc' ) {
524
544
body = this . wsdl . objectToRpcXML ( outputName , result , '' , this . wsdl . definitions . $targetNamespace ) ;
525
545
} else {
526
- const element = this . wsdl . definitions . services [ serviceName ] . ports [ portName ] . binding . methods [ methodName ] . output ;
546
+ const element = binding . methods [ methodName ] . output ;
527
547
body = this . wsdl . objectToDocumentXML ( outputName , result , element . targetNSAlias , element . targetNamespace ) ;
528
548
}
529
549
callback ( this . _envelope ( body , headers , includeTimestamp ) ) ;
530
550
} ;
531
551
532
- if ( ! this . wsdl . definitions . services [ serviceName ] . ports [ portName ] . binding . methods [ methodName ] . output ) {
552
+ if ( ! binding . methods [ methodName ] . output ) {
533
553
// no output defined = one-way operation so return empty response
534
554
handled = true ;
535
555
body = '' ;
0 commit comments