Error using Soap API from script
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).
My code is as follows:
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:
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 b开发者_开发知识库e serialized because it does not have a parameterless constructor. (line 21)
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)?
Thanks!
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.
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"),
with:
Xml.attribute("xmlns", "ZuluTrade.WebServices"),
精彩评论