【问题标题】:wcf client config not getting values from server app.configwcf 客户端配置未从服务器 app.config 获取值
【发布时间】:2011-06-08 13:50:48
【问题描述】:

我已经在服务器配置文件中定义了 maxBufferSize = 2147483647, maxBufferPoolSize = 2147483647, maxReceivedMessageSize = 2147483647,但是当我生成客户端配置文件时,所有这些参数的值都是默认的,我必须手动编辑它们。这就是我生成客户端配置文件的方式

svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config net.tcp:/
/localhost:4365/MyService

另外,由于我在 maxBufferSize、maxBufferPoolSize、maxReceivedMessageSize 和 maxItemsInObjectGraph 中使用最大值,这会影响性能吗?

--服务器配置值--

    <bindings>
      <netTcpBinding>
        <binding name="MySvc_InsecureTcp" closeTimeout="00:01:10"  openTimeout="00:01:10" receiveTimeout="24.20:31:23.6470000"
                        listenBacklog="1000" maxConnections="1000" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
          <security mode="None">
            <transport protectionLevel="None" />
          </security>
        </binding>
        <binding name="MySvc_mexBinding" closeTimeout="00:01:10"  openTimeout="00:01:10" receiveTimeout="24.20:31:23.6470000"
                        listenBacklog="1000" maxConnections="1000" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
          <security mode="None">
            <transport protectionLevel="None" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>


    <behaviors>
      <serviceBehaviors>
        <behavior name="MyService">

          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
          <serviceDebug includeExceptionDetailInFaults="false" />
          <serviceThrottling maxConcurrentCalls="30" maxConcurrentInstances="2147483647" maxConcurrentSessions="30" />
          <serviceMetadata />
        </behavior>
      </serviceBehaviors>
    </behaviors>

<services>

      <service name="MyNameSpace.MyService" behaviorConfiguration="MyService">
        <endpoint address="" binding="netTcpBinding" contract="MyNameSpace.IMyService"
                  bindingConfiguration="MySvc_InsecureTcp" name="netTcpMySvc" >
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>

        <endpoint address="mex" binding="netTcpBinding" contract="IMetadataExchange"
                  bindingConfiguration="MySvc_mexBinding" name="mexMySvc"  />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:4365/MyService"/>
          </baseAddresses>
        </host>

      </service>
    </services>

--在做了一些测试之后--

maxItemsInObjectGraph 不包含在客户端配置文件中。如果客户端发送大对象,maxItemsInObjectGraph 应该手动更改。

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

【问题讨论】:

    标签: wcf wcf-binding wcf-client


    【解决方案1】:

    并非在服务上定义的每个配置值都通过元数据传递给客户端。缓冲区大小和读取器配额就是一个例子,因为通信中的每个参与者都可以设置自己的值 - 这些值可以防御拒绝服务攻击,并且可以根据交换的消息在服务和客户端之间有所不同。例如,如果您只想上传大型数据集,则必须在服务上正确设置它们,而无需在客户端上修改它们。下载有相反的效果。

    【讨论】:

    • 所以如果我希望客户端向我发送大对象,我应该在服务器端更改这些值,但在客户端不更改?
    • 如果您不想将大对象发送回客户端,则无需更改。
    • 这是一种单向操作。客户没有得到任何回报。
    • 在这种情况下,您可以在客户端使用默认值。
    【解决方案2】:

    这是正常的。这些属性仅限于该配置文件,并且不会跨越服务。客户端和服务器可以有不同的大小限制,主要是为了帮助保护服务器免受过长的请求(客户端可能期望的)。

    【讨论】:

      猜你喜欢
      • 2012-04-24
      • 2011-12-03
      • 1970-01-01
      • 2023-03-21
      • 2020-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-26
      相关资源
      最近更新 更多