node.js - SOAPUI 和 Node.JS/Request-AccessException

标签 node.js soap soapui estes-express-api

我正在尝试使用使用 SOAP 的 Estes 货件跟踪 Web 服务构建一个货件跟踪工具。我与他们的网络支持进行了交谈,他们能够使用 SOAPUI 创建工作请求,该请求使用我的凭据接收有效响应。看来我的问题是无法使用 node.js 在 SOAPUI 中复制请求/响应。为什么我无法在 node.js 中复制 SOAPUI 请求/响应?

以下是 Estes Web 支持使用的来自 SOAPUI 的工作原始请求:

POST https://api.estes-express.com:443/ws/estesrtshipmenttracking.base.ws.provider.soapws:EstesShipmentTracking/estesrtshipmenttracking_base_ws_provider_soapws_EstesShipmentTracking_Port HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "estesrtshipmenttracking_base_ws_provider_soapws_EstesShipmentTracking_Binder_shipmentTracking"
Content-Length: 468
Host: api.estes-express.com:443
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Authorization: Basic XXXXX

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="https://api.estes-express.com/ws/tools/shipment/tracking/v1.1/">
   <soapenv:Header/>
   <soapenv:Body>
      <v1:shipmentTracking>
         <search>
            <requestID>testroger</requestID>
            <!--Optional:-->
            <pro>XXXXXX</pro>
         </search>
         <debug>N</debug>
      </v1:shipmentTracking>
   </soapenv:Body>
</soapenv:Envelope>

我在上面省略了 base 64 编码的 Basic Auth 信息,但我向你保证我在我的请求中使用了完全相同的值。

我的请求如下,使用 node.js。我应该注意,我在我的请求中提供了代理信息,但我已经验证它在其他请求函数中有效。

function estes(obj) {

    var auth = 'Basic XXXXXXX'

    var url = 'https://api.estes-express.com:443/ws/estesrtshipmenttracking.base.ws.provider.soapws:EstesShipmentTracking/estesrtshipmenttracking_base_ws_provider_soapws_EstesShipmentTracking_Port'

    const request = require('request')
    const fs = require('fs');
    const xml = fs.readFileSync('estessample.xml', 'utf-8');

    request.post({
        uri: url,
        headers: {
            'SOAPAction': 'estesrtshipmenttracking_base_ws_provider_soapws_EstesShipmentTracking_Binder_shipmentTracking',
            'Content-Type': 'text/xml;charset=UTF-8',
            'Content-Length': xml.length,
            'Host': 'api.estes-express.com:443',
            'Authorization': auth
        },
        proxy: 'XXXXXX',
        body: xml
    }, function (error, response, body) {
        console.log(body)

        fs.writeFile("response.txt", body, (err) => {
            if (err) console.log(err);
            console.log("Successfully Written to File.");
        });
    })
}

这是我发布到他们的服务 (estessample.xml) 的 XML,这与 Estes 网络服务团队在上面使用的相同:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="https://api.estes-express.com/ws/tools/shipment/tracking/v1.1/">
   <soapenv:Header/>
   <soapenv:Body>
      <v1:shipmentTracking>
         <search>
            <requestID>testroger</requestID>
            <!--Optional:-->
            <pro>XXXXXXX</pro>
         </search>
         <debug>N</debug>
      </v1:shipmentTracking>
   </soapenv:Body>
</soapenv:Envelope>

最后,这是我在 response.xml 中收到的错误:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <soapenv:Fault>
         <faultcode>soapenv:Client</faultcode>
         <faultstring>[ISS.0088.9164] Access to WSDescriptor estesrtshipmenttracking.base.ws.provider.soapws:EstesShipmentTracking denied.</faultstring>
         <faultactor>http://api.estes-express.com/tools</faultactor>
         <detail>
            <webM:exception xmlns:webM="http://www.webMethods.com/2001/10/soap/encoding">
               <webM:className>com.wm.app.b2b.server.AccessException</webM:className>
               <webM:message xml:lang="">[ISS.0088.9164] Access to WSDescriptor estesrtshipmenttracking.base.ws.provider.soapws:EstesShipmentTracking denied.</webM:message>
            </webM:exception>
         </detail>
      </soapenv:Fault>
   </soapenv:Body>
</soapenv:Envelope>

最佳答案

该错误是由于身份验证错误造成的。我刚刚尝试访问端点并收到类似的错误。

我相信你正在使用这个 Node 模块 https://github.com/request/request

在查看您共享的代码后,我认为这可能是由于您形成 POST 请求的方式所致。我建议更彻底地阅读 request 模块文档。

request.post({
    uri: url,
    headers: {
        'SOAPAction': 'estesrtshipmenttracking_base_ws_provider_soapws_EstesShipmentTracking_Binder_shipmentTracking',
        'Content-Type': 'text/xml;charset=UTF-8'
    },
    'auth': {
      'user': '<username>',
      'pass': '<password>',
    },
    body: xml,
}, function (error, response, body) {
   // Code Omitted
})

上面显示的简化示例。 注意 auth 部分。该模块还将负责设置 content-length header 。

关于node.js - SOAPUI 和 Node.JS/Request-AccessException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56718567/

相关文章:

javascript - 从单个上 Node 连接的两端公开的远程接口(interface)

java - 从 GWT 客户端调用 SOAP Web 服务

.net - 使用不同的 X509 证书配置 WCF SOAP 请求/响应的加密和签名

web-services - SharePoint 2010 : consuming web services from NetSuite - 403 Forbidden error

c# - WCF - 使用 SoapUI 测试时出现 SOAP 操作不匹配错误

node.js - 如何加速 MongoDB count() 查询?

javascript - 如何使用 javaScript 从实时数据库、Firebase 函数中的所有 randomId 中获取特定键值

rest - SOAPUI 错误 : Attempted read from closed stream for JSON POST to redirect to GET after 302

javascript - 每 n 秒运行一次异步函数,如果异步函数花费的时间超过 n 秒则等待

c# - PayPal SOAP API - 版本不受支持