【问题标题】:node-soap - Proper method of calling functionnode-soap - 调用函数的正确方法
【发布时间】:2015-12-14 17:34:54
【问题描述】:

我对 SOAP 完全一无所知,哈哈,但是我的软件的一个重要部分需要我将它用于特定的 Web 服务。 Web 服务的文档是为 .net 编写的,因此我更难理解我需要在这里做什么。最重要的是,它们需要身份验证。

对于连接我不需要授权,所以我可以检索描述函数的结果。它们如下:

I20151214-09:20:20.381(-8)? Getting inside soap client creation method
I20151214-09:20:20.722(-8)? Exception while invoking method 'createSoapClient' TypeError: Cannot call method 'describe' of undefined
I20151214-09:20:20.723(-8)?     at Object.Soap.createClient (packages/zardak_soap/packages/zardak_soap.js:37:1)
I20151214-09:20:20.724(-8)?     at [object Object].Meteor.methods.createSoapClient (controllers/server/testFiles.js:21:1)
I20151214-09:20:20.724(-8)?     at maybeAuditArgumentChecks (livedata_server.js:1698:12)
I20151214-09:20:20.725(-8)?     at livedata_server.js:708:19
I20151214-09:20:20.725(-8)?     at [object Object]._.extend.withValue (packages/meteor/packages/meteor.js:1013:1)
I20151214-09:20:20.726(-8)?     at livedata_server.js:706:40
I20151214-09:20:20.726(-8)?     at [object Object]._.extend.withValue (packages/meteor/packages/meteor.js:1013:1)
I20151214-09:20:20.726(-8)?     at livedata_server.js:704:46
I20151214-09:20:20.727(-8)?     at tryCallTwo (C:\Users\Media Center\AppData\Local\.meteor\packages\promise\0.5.1\npm\node_modules\meteor-promise\node_modules\promise\lib\core.js:45:5)
I20151214-09:20:20.727(-8)?     at doResolve (C:\Users\Media Center\AppData\Local\.meteor\packages\promise\0.5.1\npm\node_modules\meteor-promise\node_modules\promise\lib\core.js:171:13)
I20151214-09:20:21.996(-8)? Getting inside the return of the create client
I20151214-09:20:22.007(-8)? { PRIMEStandardV1_1:
I20151214-09:20:22.008(-8)?    { PRIMEStandardV1_1Soap:
I20151214-09:20:22.009(-8)?       { RunTrip: [Object],
I20151214-09:20:22.009(-8)?         ReverseGeocode: [Object],
I20151214-09:20:22.010(-8)?         FindLocationsInRadius: [Object],
I20151214-09:20:22.010(-8)?         FindLocationsOnRoute: [Object],
I20151214-09:20:22.010(-8)?         FindLocationsInState: [Object],
I20151214-09:20:22.011(-8)?         GetAverageDieselPriceInState: [Object],
I20151214-09:20:22.012(-8)?         TestRadiusGeofence: [Object],
I20151214-09:20:22.012(-8)?         TestRouteGeofence: [Object],
I20151214-09:20:22.013(-8)?         RunSimpleTrip: [Object],
I20151214-09:20:22.013(-8)?         Geocode: [Object],
I20151214-09:20:22.014(-8)?         GetTodaysUSDieselAverage: [Object],
I20151214-09:20:22.014(-8)?         GetTodaysCanadianDieselAverage: [Object],
I20151214-09:20:22.015(-8)?         GetTripDistance: [Object],
I20151214-09:20:22.016(-8)?         ValidateLocation: [Object] },
I20151214-09:20:22.017(-8)?      PRIMEStandardV1_1Soap12:
I20151214-09:20:22.017(-8)?       { RunTrip: [Object],
I20151214-09:20:22.018(-8)?         ReverseGeocode: [Object],
I20151214-09:20:22.019(-8)?         FindLocationsInRadius: [Object],
I20151214-09:20:22.021(-8)?         FindLocationsOnRoute: [Object],
I20151214-09:20:22.021(-8)?         FindLocationsInState: [Object],
I20151214-09:20:22.022(-8)?         GetAverageDieselPriceInState: [Object],
I20151214-09:20:22.022(-8)?         TestRadiusGeofence: [Object],
I20151214-09:20:22.023(-8)?         TestRouteGeofence: [Object],
I20151214-09:20:22.023(-8)?         RunSimpleTrip: [Object],
I20151214-09:20:22.024(-8)?         Geocode: [Object],
I20151214-09:20:22.025(-8)?         GetTodaysUSDieselAverage: [Object],
I20151214-09:20:22.025(-8)?         GetTodaysCanadianDieselAverage:   [Object],
I20151214-09:20:22.026(-8)?         GetTripDistance: [Object],
I20151214-09:20:22.026(-8)?         ValidateLocation: [Object] } } }

无壳: I20151216-11:53:14.658(-8)? {字典: I20151216-11:53:14.658(-8)? {'缓存控制':'私人', I20151216-11:53:14.659(-8)? '内容类型':'文本/xml;字符集=utf- 8', I20151216-11:53:14.659(-8)?服务器:'Microsoft-IIS/7.0', I20151216-11:53:14.660(-8)? 'x-aspnet-version': '4.0.30319', I20151216-11:53:14.660(-8)? 'x-powered-by': 'ASP.NET', I20151216-11:53:14.661(-8)?日期:'格林威治标准时间 2015 年 12 月 16 日星期三 19:40:29', I20151216-11:53:14.661(-8)?连接:'关闭', I20151216-11:53:14.662(-8)? '内容长度': '441' } }, I20151216-11:53:14.662(-8)?管道:[功能], I20151216-11:53:14.663(-8)? addListener:[功能:addListener], I20151216-11:53:14.664(-8)? on:[功能:addListener], I20151216-11:53:14.665(-8)?暂停:[功能], I20151216-11:53:14.665(-8)?简历:[功能], I20151216-11:53:14.666(-8)?阅读:[功能], I20151216-11:53:14.666(-8)?正文:'soap:ServerServer 无法处理请求。 ---> 对象引用未设置为对象的实例。 } I20151216-11:53:16.716(-8)?错误:[对象对象] I20151216-11:53:16.722(-8)? {信封:{正文:{故障:[对象]}}} I20151216-11:53:16.723(-8)?未定义

如您所见,我可以连接。现在让我失望的部分是实际调用这些函数之一。下面是我用来尝试调用“RunSimpleTrip”的代码。但是,当我在控制台记录结果时,它是一大堆消息,最终在我的 cmd 窗口上运行缓冲区,我只能看到一些没有意义的方法。

var url = 'http://prime.promiles.com/Webservices/v1_1/PRIMEStandardV1_1.asmx?wsdl';

        var simpleTrip = {
                            AvoidTollRoads:     false,
                            BorderOpen:         true,
                            RoutingMethod:      "PRACTICAL",
                            TripLegs:           [{LocationText: "77611"},
                                                 {LocationText: "90210"}] 
                         }

        Soap.createClient(url, function(err, client) {
            console.log(client.describe());
            client.setSecurity(new Soap.BasicAuthSecurity('hoperd', 'mailaaron', 'bkkyt'));
            client.PRIMEStandardV1_1.PRIMEStandardV1_1Soap.RunSimpleTrip(simpleTrip, function(err, result, raw, soapHeader) {
                //console.log("Result: ");
                console.log(result);
                console.log("Error: " + err.root);
                console.log(err.root);
                console.log(soapHeader);
                // result is a javascript object
                // raw is the raw response
                // soapHeader is the response soap header as a javascript object
            })
        });

根据 API 的文档,这是他们使用 .net 调用相同函数的方式

    PRIMEEnterpriseV1 PRIME = new PRIMEEnterpriseV1();

//Authorization Credentials
Credentials c = new Credentials();
c.Username = "MyUsername;
c.Password = "MyPassword";
c.CompanyCode ="MyCompanyCode";

SimpleTrip st = new SimpleTrip();
st.AvoidTollRoads = false;
st.BorderOpen = true;
st.RoutingMethod = com.promiles.PRIME.Enterprise.RouteMethod.PRACTICAL;

TripLeg[] Legs = new TripLeg[2];

//Origin
TripLeg t = new TripLeg();
t.LocationText = "77611";
Legs[0] = t;

//Destination
t = new TripLeg();
t.LocationText = "90210";
Legs[1] = t;

st.TripLegs = Legs;

//Call Function
SimpleTrip rt = PRIME.RunSimpleTrip(c, st);

我希望我们那里的某个人对我有这个谜团的线索,或者可以为我指出正确的方向,以了解如何正确连接这个。任何和所有的帮助将不胜感激。

【问题讨论】:

  • Node-soap 在错误中包含整个响应对象,这可能是输出对于您的控制台来说太大的原因。而不是console.log("Error: " + err); 尝试console.log("Error: " + err.root);。这可能会给你一些更有用的信息。在您的第一个输出中,您的初始 createClient 调用似乎失败并返回 null client (Cannot call method 'describe' of undefined)。该回调的错误是什么样的?
  • 我添加了 'console.log("Error: " + err.root);'它产生以下内容:错误:[object Object],所以我只是 console.log(err.root);它会产生这样的结果:{ Envelope: { Body: { Fault: [Object] } } },
  • 但我能从神秘的结果消息中破译出的一件事是:body: 'schemas.xmlsoap.org/soap/envelope" xmlns:xsi="w3.org/2001/XMLSchema-instance" xmlns:xsd="w3.org/2001/… 无法处理请求。--->对象引用未设置为对象的实例。'
  • 至于第一个失败的描述,这不是我调用的,而是客户端创建调用调用的。
  • console.log 在嵌套对象上使用 [Object]。要查看所有嵌套数据,请使用 JSON.stringify(err.root)

标签: node.js web-services soap meteor soap-client


【解决方案1】:

因此,经过多次反复试验,我能够弄清楚这一点。下面的代码用于调用 SimpleTrip 并从服务器返回正确的响应。我的 TripLegs arg 仍然不是 SOAP 正在寻找的 100% 正确,但代码和调用它的方式是正确的。

var url = 'http://prime.promiles.com/Webservices/v1_1/PRIMEStandardV1_1.asmx?wsdl';
        var credentials = { Username:       "xxxxx",
                            Password:       "xxxxxx",
                            CompanyCode:    "xxxxx"
                          };

        var simpleTrip = {
                            AvoidTollRoads:     false,
                            BorderOpen:         true,
                            RoutingMethod:      "PRACTICAL",
                            VehicleType:        "Tractor2AxleTrailer2Axle", 
                            TripLegs:           [{Location: {LocationText: "77611"}},
                                                {Location: {LocationText: "90210"}}] 
                         }

        args = {c: credentials, BasicTrip: simpleTrip};

        Soap.createClient(url, function(err, client) {
            console.log(err);
            console.log(simpleTrip);
            client.RunSimpleTrip(args, function(err, result, raw, soapHeader) {
                console.log(result);
                //console.log(err.root);
                console.log(err.root.Envelope);
            })
        });

【讨论】:

  • 这段代码是否足以进行客户端肥皂调用?还是我需要像他们在文档中制作的那样制作服务器
猜你喜欢
  • 2021-08-26
  • 2015-07-23
  • 1970-01-01
  • 1970-01-01
  • 2021-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-28
相关资源
最近更新 更多