0

我目前正在尝试使用 WCF、WShttpBinding 在 winform 应用程序中创建 Web 服务。其中一种方法返回字典。客户端,RTD 服务器将调用此方法来检索字典。

由于某种原因,当字典变得太大(0.6MB +)时,会抛出通信异常。我已经尝试在客户端和服务器端增加以下参数的大小,但它仍然不起作用。有人可以告诉我我做错了什么吗?谢谢。

binding.MaxReceivedMessageSize
binding.MaxBufferPoolSize
binding.SendTimeout 
binding.OpenTimeout
binding.ReceiveTimeout 
binding.ReaderQuotas.MaxStringContentLength 
binding.ReaderQuotas.MaxDepth 
binding.ReaderQuotas.MaxBytesPerRead
4

1 回答 1

3

在文件中添加behavior配置App.config

  • 在服务器上:

 

<behaviors>
    <serviceBehaviors>
        <behavior name="MyServiceBehavior">
            <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
    </serviceBehaviors>
</behaviors>
  • 在客户端:

 

<behaviors>
    <endpointBehaviors>
        <behavior name="MyClientBehavior">
            <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
    </endpointBehaviors>
</behaviors>

请注意,这2147483647是最大值,也许您不需要那么多。


并且不要忘记引用您的服务和端点中的行为:

  • 在您的服务器上(如果它托管某些服务,则在您的客户端上):

 

<service name="SomeService" behaviorConfiguration="MyServiceBehavior">
    <endpoint binding="WShttpBinding" 
              bindingConfiguration="MyBindingConf" 
              contract="SomeContract"/>
</service>
  • 在您的客户端上:

 

<endpoint binding="WShttpBinding" 
          bindingConfiguration="MyBindingConf"
          behaviorConfiguration="MyServiceBehavior" 
          contract="SomeContract" 
          name="SomeName" />
于 2011-11-02T11:22:40.723 回答