【问题标题】:Soap web service call using Node JS使用 Node JS 的 Soap Web 服务调用
【发布时间】:2017-09-07 06:14:17
【问题描述】:

我是 nodejs 的新手,我正在尝试使用它的 soap 功能来调用soap web 服务。我在网上看到了各种示例,但无法弄清楚如何将它们与我拥有的数据一起使用。

我从我的 Java 应用程序中获得了肥皂请求,并在 SoapUI 应用程序中使用它,它工作得非常好。刚刚使用了 wsdl 链接和 XML。我需要一个关于如何将这些与 nodejs 一起使用的示例。提前致谢。

以下是我在 SoapUI 应用中使用的详细信息 -

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>

【问题讨论】:

    标签: node.js web-services soap


    【解决方案1】:

    您可以使用request,如下例所示,只需使用正确的SOAPAction(来自您的wsdl,它是runTransaction

    我通常使用Boomerang 创建虚拟示例请求,并在需要时获取正确的 SOAPAction 和其他标头。

    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)
    })
    

    【讨论】:

    • 非常感谢,效果很好。我想知道是否有一种方法可以传递代理信息,以防我在 vpn 中对其进行测试?
    • @PragyanandiptaTripathy 你可以使用环境变量,request: HTTP_PROXY, HTTPS_PROXY, NO_PROXY 或将proxy 添加到选项中
    猜你喜欢
    • 2017-05-09
    • 1970-01-01
    • 2016-05-21
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 2010-09-19
    相关资源
    最近更新 更多