jdrucey
jdrucey

Reputation: 35

How to choose an wsdl operation in node-soap

I'm using the node-soap package to consume the following SOAP service: https://paymentsuat.mppglobal.com/interface/mpp/ipaypaymentpages/ipaypaymentpages.asmx?wsdl

For the iPayPaymentPagesSoap port, there are two operations with the same name, but different parameters.

Using the describe function node-soap only shows the last operation for each port type. Is there a way of selecting which operation is called?

<wsdl:portType name="iPayPaymentPagesSoap">
    <wsdl:operation name="CreateSession">
        <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
        Retrieves a Guid from the system populated with details. Used in conjunction with ipayment pages.
        </wsdl:documentation>
        <wsdl:input name="CreateSessionBySOAP" message="tns:CreateSessionBySOAPSoapIn"/>
        <wsdl:output name="CreateSessionBySOAP" message="tns:CreateSessionBySOAPSoapOut"/>
    </wsdl:operation>
    <wsdl:operation name="CreateSession">
        <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
        Retrieves a Guid from the system populated with user details. Used in conjunction with ipayment pages.
        </wsdl:documentation>
        <wsdl:input name="CreateSessionByGET" message="tns:CreateSessionByGETSoapIn"/>
        <wsdl:output name="CreateSessionByGET" message="tns:CreateSessionByGETSoapOut"/>
    </wsdl:operation>
</wsdl:portType>

Renders to:

{
    iPayPaymentPages: {
        iPayPaymentPagesSoap: {
            CreateSession: {
                input: {
                    affiliateId: "s:int",
                    password: "s:string"
                },
                output: {
                    CreateSessionByGETResult: {
                        Guid: "s:string",
                        ErrorNumber: "s:int",
                        ErrorMessage: "s:string",
                        targetNSAlias: "tns",
                        targetNamespace: "https://secure1.mppglobal.com/interface/ipaypaymentpages/ipaypaymentpages.asmx"
                    }
                }
            }
        }
    }
}

However, i'm aiming to use CreateSession with the CreateSessionBySOAP parameters, but node-soap defaults to CreateSessionByGET.

*I have no control over the WSDL and would much rather not use SOAP with Node.js, but i'm stuck with it in this case!

Upvotes: 1

Views: 1779

Answers (1)

Edilberto Samudio
Edilberto Samudio

Reputation: 26

i get stuck within the same behavior, seems that into node-soap/lib/client.js uses the wsdl as an object or dom object, but at wsdl:portTypes it only represents the last operation element. In my case, I have 4 operations with the same name, so here is how I solve it.

        soap.createClient(url, options, function(err, client) {

        var method = client.wsdl.definitions.services.[Service].ports.[Port].binding.methods['CreateSession'];
        var location = client.wsdl.definitions.services.[Service].ports.[Port].location;

        //change method $name, method input $name
        method.$name = 'CreateSessionBySOAP';
        method.input.$name = 'CreateSessionBySOAP';

        var def= client._defineMethod(method, location);
        //invoke the method
        def(args, options, function(err, result) {
           console.log(JSON.stringify(result));
        });
         console.log(client.lastMessage);
         console.log(client.lastResponse);
});

Upvotes: 1

Related Questions