简体   繁体   中英

Soap web service call using Node JS

I am new to nodejs and trying to use it's soap feature to make a soap web service call. I saw various examples on the net but not able to figure out how to use them with the data I have.

I got the soap request from my Java application and use it in SoapUI application and it works absolutely fine. Just used the wsdl link and the XML. I need an example on how to use these with nodejs. Thanks in advance.

Below are the details I used in SoapUI app -

WSDL - https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_1.141.wsdl

xml -

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header>
        <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
            <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-*****">
                <wsse:Username>*****</wsse:Username>
                <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">*****</wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>
    </soapenv:Header>
    <soapenv:Body>
        <requestMessage xmlns="urn:schemas-cybersource-com:transaction-data-1.84">
            <merchantID>*****</merchantID>
            <merchantReferenceCode>*****</merchantReferenceCode>
            <clientLibrary>Java Axis WSS4J</clientLibrary>
            <clientLibraryVersion>1.4/1.5.1</clientLibraryVersion>
            <clientEnvironment>Windows NT (unknown)/6.2/Sun Microsystems Inc./1.6.0_20</clientEnvironment>
            <billTo>
                <street1>2nd Street</street1>
                <city>test</city>
                <state>AL</state>
                <postalCode>12345</postalCode>
                <country>US</country>
            </billTo>
            <item id="0">
                <unitPrice>2650.0</unitPrice>
                <quantity>1</quantity>
                <productCode>*****</productCode>
                <productName>*****</productName>
                <productSKU>*****</productSKU>
            </item>
            <taxService run="true">
                <sellerRegistration />
            </taxService>
        </requestMessage>
    </soapenv:Body>
</soapenv:Envelope>

You can use request as below example, just use correct SOAPAction (from your wsdl, it's runTransaction )

I usually use Boomerang to create dummy sample request and get correct SOAPAction and others headers if needed.

const request = require('request')

const xml = '<yourxml>'
const opts = {
    body: xml,
    headers: {
        'Content-Type': 'text/xml; charset=utf-8',
        SOAPAction: 'runTransaction'
    }
}

const url = 'https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_1.141.wsdl'

const body = request.post(url, opts, (err, response) => {
    console.log('response', response.body)
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM