使用.Net 4的API连接到eTapestry会让我感到异常:
ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: name
非常无用,因为name
不是我的代码中的参数,也不是我可以在任何地方插入的代码。
连接代码:
var client = new ETap.MessagingServiceClient();
client.login(username, password);
var funds = client.getFunds(false);
奇怪的ArgumentOutOfRangeException
被抛到最后一行,而不是在登录时 - 该呼叫成功。
答案 0 :(得分:1)
两个问题:
1)eTapestry API使用并要求使用cookies,这在使用.Net Web服务时可能会异常。晦涩难懂:
ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: name`
在处理cookie身份验证的层中被抛出(或者更确切地说,失败)。解决方案很简单 - 将allowCookies="true"
添加到绑定中:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="ETap"
allowCookies="true"
maxReceivedMessageSize="1048576">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://bos.etapestry.com/v2messaging/service?WSDL"
binding="basicHttpBinding" bindingConfiguration="ETap"
contract="ETap.MessagingService" name="ETap" />
</client>
</system.serviceModel>
另请注意,我已将maxReceivedMessageSize
增加到1mb(1048576),因为默认值65536可能非常小,并且eTapestry查询通常会超出如此小的尺寸。
2)ETapestry的文档说明他们可以随时移动您的数据存储,如果他们这样做,您的登录将成功但返回您应该使用的新端点的名称。他们在PHP中的示例代码只是使用if
语句来重新执行整个登录过程,但是他们没有解释是否有任何保证这不会重复发生。例如,您可能尝试登录BOS,发现您已被定向到SNA,在那里登录,并发现您已被指向另一个地方 - 毕竟您的登录之间有时间并且不清楚eTapestry之间的时间表是什么移动。所以我们将使用while循环:
var client = new ETap.MessagingServiceClient();
string sessionEndpoint = client.login(username, password);
int attempts = 0;
while (!String.IsNullOrEmpty(sessionEndpoint))
{
if (attempts++ > 10)
throw new Exception("ETapestry failed to provide a final endpoint.");
client = new ETap.MessagingServiceClient("ETap", sessionEndpoint);
sessionEndpoint = client.login(username, password);
}
在循环中使用最大值来保护我们免受外部系统的影响,导致我们陷入无限循环。
这足以让他们的API方法调用成功。