首页 > 解决方案 > 增加 WCF 服务终结点大小配置的问题

问题描述

我有一个托管 WCF 服务(通过 IIS 的 wcf 文件公开技术)的 asp.net 项目,该项目大约在 10 年前组合在一起。检索内容的服务上存在大于默认 75K 限制的操作。绑定上的服务配置(在 web.config 中)属性已调整为大于默认值并且工作正常。ASP.NET 项目在 VS2017/2019 中进行了升级——并且(我假设)项目进行了调整(不知何故)。上述服务操作不再起作用。我做了很多调查,所有解决方案都得到了处理(这是有道理的,因为项目的原始版本正在运行)。我什至经历了以最少配置构建新 web.config 的过程,但仍然无法正常工作。我还调整了服务以包含可用于在代码中配置端点配置的配置操作。它也没有工作。为此,我有以下内容:

    public static void Configure(ServiceConfiguration config)
    {            
        BasicHttpBinding binding = new BasicHttpBinding();
        binding.MaxReceivedMessageSize  = int.MaxValue;
        binding.MaxBufferSize           = int.MaxValue;
        binding.MaxBufferPoolSize       = int.MaxValue;

        binding.BypassProxyOnLocal = true;

        binding.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas()
        {
            MaxStringContentLength  = int.MaxValue,
            MaxDepth                = int.MaxValue,
            MaxArrayLength          = int.MaxValue,
            MaxBytesPerRead         = int.MaxValue,
            MaxNameTableCharCount   = int.MaxValue
        };

        var endpoint = new ServiceEndpoint(
            ContractDescription.GetContract(
                    typeof(IAuthenticateServicePack)),binding,new 
         EndpointAddress("http://localhost:49437/WCFSevices/AuthenticateServicePack.svc"));

        //MyEndpointBehavior Behavior = new MyEndpointBehavior();
        //endpoint.Behaviors.Add(Behavior);

        config.AddServiceEndpoint(endpoint);
    }

web.config 定义如下

 <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
multipleSiteBindingsEnabled="true" 
/>

<behaviors>
  <serviceBehaviors>
    <behavior name="ServicePack.ServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500" 
/>
    </behavior>
  </serviceBehaviors>      
</behaviors>

<bindings>
  <basicHttpBinding>
    <clear />

    <binding name="myBindingForBigArrays" maxReceivedMessageSize="2147483647" 
transferMode="Buffered">
      <readerQuotas 
        maxDepth="32" 
        maxStringContentLength="2147483647" 
        maxArrayLength="2147483647" 
        maxBytesPerRead="4096" 
        maxNameTableCharCount="10000"             
      />
    </binding>
  </basicHttpBinding>
</bindings>

<services>
  <service name="Lapp.WebAdmin.Mvc.WCFSevices.AuthenticateServicePack" 
behaviorConfiguration="ServicePack.ServiceBehavior">
    <endpoint address="" binding="basicHttpBinding" 
bindingConfiguration="myBindingForBigArrays" 
contract="Lapp.WebAdmin.Mvc.WCFSevices.IAuthenticateServicePack" />

    <host>
      <timeouts closeTimeout="00:01:00" />
    </host>

     </service>
   </services>
</system.serviceModel>

出于某种原因 - 更新的 asp.net 项目似乎没有处理 WCF 服务端点配置。有没有人遇到过这个问题?

注意:我可以测试旧版本的服务并且工作正常 - 并且使用新配置查看旧配置 - 无法识别任何可能导致新版本不使用大小限制设置的修改。

标签: wcf

解决方案


推荐阅读