.net - WCF - 客户端代理配置与服务 web.config 不匹配

标签 .net wcf web-services configuration

我有一个简单的 WCF 服务,需要处理大型数据流,因此我有很多配置值都高于默认值。我最近将所有代码转移到一个新的、重组的解决方案中,并且我刚刚转移了该服务。但是,当我尝试生成客户端代理(使用 WCFTestClient.exe 或 VS2008 中的“添加服务引用”)时,客户端代理配置中的值与我为服务设置的值不匹配。

这是服务器配置 - 请注意 maxBufferSize、maxReceivedMessageSize、maxStringContentLength 和 MaxArrayLength 的增加的值

  <system.serviceModel>
    <bindings>    
      <basicHttpBinding>
        <binding name="default" maxBufferSize="5000000" maxReceivedMessageSize="5000000">
          <readerQuotas maxStringContentLength="5000000" maxArrayLength="5000000" />
          <!-- turn this setting on to require SSL/https -->
          <!-- <security mode="Transport" /> -->
        </binding>       
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Consent.Service.SubjectConsentServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="Consent.Service.SubjectConsentServiceBehavior"
        name="Consent.Service.SubjectConsentService">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="default"
          contract="Consent.Service.ISubjectConsentService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>

这是VS2008通过“添加服务引用”生成的代理

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_ISubjectConsentService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://server/Consent/services/SubjectConsent.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISubjectConsentService"
            contract="ServiceReference1.ISubjectConsentService" name="BasicHttpBinding_ISubjectConsentService" />
    </client>
</system.serviceModel>

客户端代理将这 4 个值设置为默认值。

您知道为什么客户端使用默认值吗?

最佳答案

服务器配置文件中设置的值不会作为 Web 服务元数据的一部分公开(因为它们与传输层相关,而不是服务本身),因此客户端(或者在本例中为“添加服务引用”功能)无法自动找到它们。 (“添加服务引用”所做的只是请求 WSDL 并生成相应的类;它无权访问配置文件中与传输相关的设置。)

因此,您需要在客户端和服务器上覆盖它们。

关于.net - WCF - 客户端代理配置与服务 web.config 不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/652048/

相关文章:

wcf - IIS7、ARR 和 WCF……我们可以对应用服务器进行负载平衡吗?

.net - WCF - 基于消息的安全和 SSL 加速器

.net - wcf 绑定(bind)接收超时

wcf - 如何使用用户名/密码 + SSL 使用 WCF 配置安全 RESTful 服务

c# - 程序集访问

.net - .NET 桌面应用程序的最佳崩溃报告框架?

c# - 在 C# 中将字符串拆分为两个字符

C#:从 INI 中删除部分及其键的最简单方法是什么

web-services - REST API 404 : Bad URI, 或缺少资源?

java - Spring mvc 3中ModelAndView类的功能