gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 11:40:53 25 4
gpt4 key购买 nike

一种愚蠢的错误,但是当我想通过服务器端服务(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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com