【问题标题】:Connect to ETapestry's API via .Net 4 Web Services (Service Reference, not Web Service)通过 .Net 4 Web 服务(服务参考,而不是 Web 服务)连接到 ETapestry 的 API
【发布时间】:2014-09-04 17:52:51
【问题描述】:

使用 .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 被抛出在最后一行,而不是在登录时 - 调用成功。

【问题讨论】:

    标签: c# asp.net web-services wcf


    【解决方案1】:

    两个问题:

    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>
    

    还请注意,我已将 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 的方法调用成功。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-06
      • 2010-11-15
      • 2011-08-28
      • 2012-08-26
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      相关资源
      最近更新 更多