c# - WCF 回调超时和 Visual Studio 灾难性故障

标签 c# .net wcf service duplex

一种愚蠢的错误,但是当我想通过服务器端服务(WCF Duplex)调用客户端时发生了这种情况:

The message could not be transferred within the allotted wcf callback timeout of 00:01:00, There was no space available in the reliable channel's transfer window

还有一些神秘的事情也发生了。在我调用服务时的登录方法中,如果用户和密码错误,我会找到发件人回调,然后在发件人上调用 GetError 方法以显示逻辑错误,如“用户错误”。这很好用,但是如果用户和密码正确并且可以访问,我会收到该错误(所有其他客户端方法都一样 - 在所有这些方法中我发送的数据多于简单的字符串,我发送了 geterror)!

编辑 2: 正如我在大多数回调方法中所说的那样,我发送了数据上下文 (LINQ to SQL) 数据类(列表或单行)之类的数据。所以这是否是我的问题!
(但这不是我第一次使用 WCF-duplex,还在回调方法中使用发送数据结构,我太震惊了。)

同样在那个错误之后我得到了这个错误,

Screen unable to process request from service http://server:15450/service.svc catastrophic failure

编辑 3: 服务配置:

 <system.serviceModel>
    <services>
      <service name="ContactServer.Business.ContactService"
               behaviorConfiguration="ServiceBehavior">
        <endpoint address=""
                  binding="wsDualHttpBinding"
                  contract="ContactServer.Business.IContactService">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange"
                  name="MexBinding"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

客户端配置

  <system.serviceModel>
    <bindings>
      <wsDualHttpBinding>
        <binding name="WSDualHttpBinding_ContactService" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
          maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
          textEncoding="utf-8" useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00" />
          <security mode="Message">
            <message clientCredentialType="Windows" negotiateServiceCredential="true"
              algorithmSuite="Default" />
          </security>
        </binding>
      </wsDualHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:1408/ContactService.svc"
        binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_ContactService"
        contract="ServiceReference.ContactService" name="WSDualHttpBinding_ContactService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>

更多信息:我使用 .NET 3.5 和 Visual Studio 2010。同样在客户端超时后我仍然遇到同样的错误,00:01:00 Time。为什么会这样?

最佳答案

问题与从 WCF 服务传输实体有关。

例如,我们有这个数据库模型: enter image description here

Entity Framework :

    public Item GetItem(int id)
    {
        var se = new SampleEntities();
        return se.Items.FirstOrDefault(i => i.Id == id);
    }

代码看起来没有错,但实际上它会返回包含所有相关项目的项目。

        var s = new SampleServiceClient();
        var item = s.GetItem(1);
        Assert.AreEqual(item.RelatedItems.Any(), true); //equal

如果我们在数据库中有多对多关系,那就特别危险了。 所以延迟加载应该被禁用(你可以在返回之前禁用它们):

var se = new SampleEntities();
se.ContextOptions.LazyLoadingEnabled = false;
return se.Items.FirstOrDefault(i => i.Id == id);

Linq to SQL

    public Item GetItem(int id)
    {
        var dc = new DataClasses1DataContext();
        return dc.Items.FirstOrDefault(i => i.Id == id);
    }

我们有一个异常(exception):

There was an error while trying to serialize parameter :GetItemResult. The InnerException message was 'Object graph for type 'WebApplication1.RelatedItem' contains cycles and cannot be serialized if reference tracking is disabled.'.

您必须打开 DataContext 图表并设置 Properties->SerializationMode->Unindirectional。 Here是一个更完整的解释。

关于c# - WCF 回调超时和 Visual Studio 灾难性故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4837461/

相关文章:

c# - 多次调用我的 WCF 服务方法

c# - Quartz Scheduler (.Net) - 为什么在运行内置 'RescheduleJob' 方法后立即触发作业?

具有 netNamedPipeBinding 性能不佳的 WCF

c# - .NET 标准 2.0 的 WCF Web 服务引用

c# - 具有由 lambda 定义的自定义 IEqualityCompare 的 HashSet 构造函数?

c# - 每次运行后 20 分钟运行线程

c# - 使用 "isostore:/"方案从 XAML 中的独立存储访问图像

c# - foreach循环中List <>中的第一个或最后一个元素

c# - IPrincipal.IsInRole() 仅在我截断角色名称时有效 - 为什么?

c# - 不支持协议(protocol) 'net.tcp'