C# 连接到ETapestry';s API通过.Net 4 Web服务(服务引用,而非Web服务)
使用.Net 4的API连接到eTapestry时,我遇到了一个异常:C# 连接到ETapestry';s API通过.Net 4 Web服务(服务引用,而非Web服务),c#,asp.net,web-services,wcf,C#,Asp.net,Web Services,Wcf,使用.Net 4的API连接到eTapestry时,我遇到了一个异常: ArgumentOutOfRangeException:指定的参数超出了有效值的范围。 参数名称:名称 非常无用,因为name不是我代码中的参数,也不是我可以在任何地方进入的代码 要连接的代码: var client = new ETap.MessagingServiceClient(); client.login(username, password); var funds = client.getFunds(false)
ArgumentOutOfRangeException:指定的参数超出了有效值的范围。
参数名称:名称
非常无用,因为name
不是我代码中的参数,也不是我可以在任何地方进入的代码
要连接的代码:
var client = new ETap.MessagingServiceClient();
client.login(username, password);
var funds = client.getFunds(false);
奇怪的是,ArgumentOutOfRangeException在最后一行抛出,而不是在登录时抛出-调用成功。两个问题:
1) eTapestry API使用并需要cookie,这在.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>
循环中的最大值可以保护我们免受外部系统的影响,从而使我们进入无限循环
这足以使对API的方法调用成功
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);
}