从脚本使用Soap API时出错 [英] Error using Soap API from script

查看:51
本文介绍了从脚本使用Soap API时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个脚本,试图使用该脚本来访问在我的浏览器中正常运行的api(导航至 http://zulutrade.com/TradeHistoryIndi​​vidual.aspx?pid=24508 ,以查看在您更改交易历史记录中可见的交易数量时,通过查看开发人员工具中的XHR请求来查看其工作情况).

I currently have a script that I am trying to use to access an api that works fine in my browser (navigate to http://zulutrade.com/TradeHistoryIndividual.aspx?pid=24508 to see it working by viewing the XHR requests in developer tools when you change the number of trades visible in the trade history).

我的代码如下:

function getHistory() {

  var wsdl = SoapService.wsdl("http://zulutrade.com/WebServices/Performance.asmx?WSDL");

  var performanceService = wsdl.getService("PerformanceWebService");

  var param = Xml.element("GetProviderTrades", [
              Xml.attribute("xmlns", "http://zulutrade.com/WebServices/Performance.asmx?WSDL"),
              Xml.element("start",["0"]),
              Xml.element("length",["100"]),
              Xml.element("sortBy",["dc"]),
              Xml.element("sortAscending",[false]),
              Xml.element("providerId",["24508"]),
              Xml.element("currencyIds",["[]"]),
              Xml.element("fromDateStr",["1984-04-24"]),
              Xml.element("toDateStr",["2011-09-10"]),
              Xml.element("validTrades",[true]),
              Xml.element("lotSize",["2"])
            ]);

  var result = performanceService.invokeOperation("GetProviderTrades", [param]);

  Logger.log(result);
}

我已经从浏览器中看到的有效载荷数据中复制了参数,但是出现以下错误:

I have copied the params from the payload data that I see in my browser, but I am getting the following error:

对于 http://zulutrade.com/WebServices/Performance.asmx 返回的代码的请求失败500.服务器响应:soap:ServerServer无法处理请求. --->生成XML文档时出错. ---> <> f__AnonymousTypee`2 [System.Int32,Z.T []]无法序列化,因为它没有无参数的构造函数. (第21行)

Request failed for http://zulutrade.com/WebServices/Performance.asmx returned code 500. Server response: soap:ServerServer was unable to process request. ---> There was an error generating the XML document. ---> <>f__AnonymousTypee`2[System.Int32,Z.T[]] cannot be serialized because it does not have a parameterless constructor. (line 21)

有人能说明我做错了什么吗?我是否需要提供某种标题数据(可能是cookie或其他东西)?

Can anyone shed any light on what I am doing wrong? Do I need to supply some kind of header data (maybe a cookie or something)?

谢谢!

推荐答案

.NET XmlSerializer对于您要对其进行序列化/反序列化的任何类型都需要无参数构造函数,因此,如果您使用的C#类没有默认构造函数作为.asmx Web服务的参数或返回值.因此,似乎Web服务代码(而不是JavaScript)可能有问题.

The .NET XmlSerializer requires a parameterless constructor for any type that you ask it to serialize/deserialize so you get this kind of error if you use a C# class that has no default constructor as a parameter or return value for a .asmx Web Service. So it looks as though there could be a problem in the Web service code rather than your JavaScript.

但是,GetProviderTrades元素的XML名称空间对我来说似乎是错误的(鉴于 http://zulutrade.com/WebServices/Performance.asmx?op=GetProviderTrades ),请尝试替换以下行:

However the XML namespace for the GetProviderTrades element looks wrong to me (given http://zulutrade.com/WebServices/Performance.asmx?op=GetProviderTrades), try replacing the line:

Xml.attribute("xmlns", "http://zulutrade.com/WebServices/Performance.asmx?WSDL"),

具有:

Xml.attribute("xmlns", "ZuluTrade.WebServices"),

这篇关于从脚本使用Soap API时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆