c# - 通过 WCF 回调发送业务对象时发生超时

标签 c# .net wcf callback

我有一个 WCF 服务,它通过回调协定实现,我试图通过它发送业务对象。我的业务对象装饰有 DataContract() 和 DataMember() 属性,它包含以下数量的属性:

  • 整数:3
  • 字符串:4
  • X元素:1
  • 其他对象:5个(也用DataContract()和DataMember()装饰

每当我尝试通过回调发送此对象时,服务就会超时。我曾尝试创建其他属性较少的对象以通过回调发送,如果只有一个属性,则可以让它通过,但如果我有不止一个属性,服务就会超时。

我的配置有问题吗?我已经尝试了默认的 wsDualHttpBinding 以及 customBinding(如下所示),并且我已经尝试了各种不同的 maxBufferSize、maxBufferPoolSize 和 maxReceivedMessageSize 设置。我不想增加超时,因为我希望这个对象能很快到达我的客户。请有人帮助我...如果我还有头发,我现在早就把它拔掉了!!!!!

我已经这样配置了我的服务:

服务器配置:

    <customBinding>
        <binding name="DualBindingConfig">
            <reliableSession flowControlEnabled="true" maxPendingChannels="128" />
            <compositeDuplex />
            <oneWay/>
            <binaryMessageEncoding/>
            <httpTransport maxReceivedMessageSize="655360000" maxBufferPoolSize="655360000" />
        </binding>
    </customBinding>
    <services>
        <service behaviorConfiguration="Agent_Utility_WCF.Callback.AgentMessagingBehavior"
            name="Agent_Utility_WCF.Callback.AgentMessaging">
            <endpoint address="" binding="customBinding" bindingConfiguration="DualBindingConfig" bindingName="AgentMessaging" contract="Agent_Utility_WCF.Callback.IAgentMessaging">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="Agent_Utility_WCF.Callback.AgentMessagingBehavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true" />
                <serviceThrottling maxConcurrentCalls="160" maxConcurrentSessions="100"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>

客户端配置:

<bindings>
    <customBinding>
        <binding name="AgentMessaging_IAgentMessaging">
            <reliableSession acknowledgementInterval="00:00:00.2000000" flowControlEnabled="true"
                inactivityTimeout="00:10:00" maxPendingChannels="4" maxRetryCount="8"
                maxTransferWindowSize="8" ordered="true" reliableMessagingVersion="Default" />
            <compositeDuplex />
            <oneWay maxAcceptedChannels="10" packetRoutable="false">
                <channelPoolSettings idleTimeout="00:02:00" leaseTimeout="00:10:00"
                    maxOutboundChannelsPerEndpoint="10" />
            </oneWay>
            <binaryMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
                maxSessionSize="2048">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
            </binaryMessageEncoding>
            <httpTransport manualAddressing="false" maxBufferPoolSize="524288"
                maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
                bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
                realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                useDefaultWebProxy="true" />
        </binding>
    </customBinding>
</bindings>
<client>
    <endpoint address="http://localhost:666/Callback/AgentMessaging.svc"
        binding="customBinding" bindingConfiguration="AgentMessaging_IAgentMessaging"
        contract="AgentMessaging.IAgentMessaging" name="AgentMessaging_IAgentMessaging">
        <identity>
            <dns value="localhost" />
        </identity>
    </endpoint>
</client>

最佳答案

将以下内容添加到您的 web.config 中:

<system.diagnostics>
    <trace autoflush="true">
        <listeners>
        </listeners>
    </trace>
    <sources>
        <source name="System.ServiceModel"
                switchValue="Information, ActivityTracing"
                propagateActivity="true">
            <listeners>
                <add name="sdt"
                     type="System.Diagnostics.XmlWriterTraceListener"
                     initializeData= "WcfDetailTrace.svclog" />
            </listeners>
        </source>
    </sources>
</system.diagnostics>

然后调用您的网络服务方法。这将在您网站的根目录中生成 WcfDetailTrace.svclog。使用 SvcTraceViewer.exe 打开此文件.这应该为您提供有关正在发生的事情的大量信息。

关于c# - 通过 WCF 回调发送业务对象时发生超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1092168/

相关文章:

c# - C# 的语法检查器

.net - 在64位系统中,32位变量占用的空间比64位对象少?

c# - 解析方法或重载构造函数

wcf - 回收 IIS7 应用程序池是否会终止任何当前正在执行的请求?

c# - Xamarin android oxyplot 在设备旋转和轴方面存在问题

c# - 将通用列表形式 DerivedClass 转换为 BaseClass

c# - WPF 中的 ValidationRule 与行为

C# 找不到已加载的程序集

wcf - 将 WCF 基于角色的安全性传递到 UI

c# - 命名空间与 WCF 的相似名称混淆