需要进行更改以采用默认 web.config 并增加 maxStringContentLength

发布于 2025-01-06 12:22:43 字数 1348 浏览 1 评论 0 原文

我需要将大量文本从我的一个客户端发送到我的服务器。为此,我知道我需要增加服务器上的 maxStringContentLength

我对此进行了大量搜索,似乎所有解决此问题的方法都从第 3 步开始

我似乎无法弄清楚步骤 1 和 2...

有人可以引导我完成这个美好而缓慢的过程吗?鉴于下面的 Web.config,我如何设置 maxStringContentLength?

这是我的 Web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <directoryBrowse enabled="true" />
  </system.webServer>
</configuration>  

背景信息:

I need to send a lot of text from one of my clients to my server. To do that I know I need to increase maxStringContentLength on the server.

I have done a ton of searching on this, and it seems that all the fixes for this start on Step 3.

I can't seem to figure out steps 1 and 2...

Can someone walk me through this nice and slow. Given my Web.config below, how can I get to set maxStringContentLength?

Here is my Web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <directoryBrowse enabled="true" />
  </system.webServer>
</configuration>  

Background info:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

思念绕指尖 2025-01-13 12:22:43

您必须修改服务端点上使用的绑定的属性。由于您没有在配置文件中提供任何内容,WCF 4.0 会自动添加每个服务合约的默认端点以及主机中定义的基地址如果服务托管在 IIS 中,则基地址就是虚拟目录。

默认端点上使用的绑定在 元素中定义。在计算机级别,映射为:

<protocolMapping>
    <add scheme="http" binding="basicHttpBinding"/>
    <add scheme="net.tcp" binding="netTcpBinding"/>
    <add scheme="net.pipe" binding="netNamedPipeBinding"/>
    <add scheme="net.msmq" binding="netMsmqBinding"/>
</protocolMapping>

在您的情况下,除非默认映射已被覆盖,否则 WCF 使用 http://myserver/Orders 虚拟目录创建默认 HTTP 端点。 href="http://msdn.microsoft.com/en-us/library/ms731361.aspx" rel="nofollow">基本HttpBinding

您可以修改 basicHttpBindingmaxStringContentLength 属性> 通过提供默认绑定配置,即无名配置,它将自动应用于使用该绑定的所有端点。

只需将此元素添加到 Web.config 的 部分即可:

<bindings>
    <basicHttpBinding>
         <binding maxReceivedMessageSize="SomeIntegerValue">
             <readerQuotas maxStringContentLength="SomeIntegerValue" />
        </binding>
    </basicHttpBinding>
</bindings>

请注意 MSDN 建议 设置 maxStringContentLengthmaxReceivedMessageSize 属性为相同的值

maxStringContentLength 属性的值不能大于
大于 maxReceivedMessageSize 属性的值。我们推荐
两个属性的值是相同的。

如果这不起作用,您可以通过在 Web.config 中添加 元素来显式定义用于默认 HTTP 端点的绑定,并相应地调整绑定配置:

<protocolMapping>
    <add scheme="http" binding="basicHttpBinding"/>
</protocolMapping>

You will have to modify the properties of the binding used on the service's endpoint. Since you haven't provided any in your configuration file, WCF 4.0 is automatically going to add a default endpoint for each service contract and base address defined in the host. If the service is hosted in IIS then the base address is the virtual directory.

The bindings used on the default endpoints are defined within the <protocolMapping> element. At the machine level, the mappings are:

<protocolMapping>
    <add scheme="http" binding="basicHttpBinding"/>
    <add scheme="net.tcp" binding="netTcpBinding"/>
    <add scheme="net.pipe" binding="netNamedPipeBinding"/>
    <add scheme="net.msmq" binding="netMsmqBinding"/>
</protocolMapping>

In your case, unless the default mappings have been overridden, WCF creates a default HTTP endpoint based on the http://myserver/Orders virtual directory using the basicHttpBinding.

You can modify the maxStringContentLength property for the basicHttpBinding by providing a default binding configuration, that is a nameless configuration, which will automatically be applied to all endpoints using that binding.

Simply add this element to your Web.config in the <system.serviceModel> section:

<bindings>
    <basicHttpBinding>
         <binding maxReceivedMessageSize="SomeIntegerValue">
             <readerQuotas maxStringContentLength="SomeIntegerValue" />
        </binding>
    </basicHttpBinding>
</bindings>

Note that MSDN recommends to set both the maxStringContentLength and maxReceivedMessageSize properties to the same value:

The value of the maxStringContentLength attribute cannot be greater
than the value of the maxReceivedMessageSize attribute. We recommend
that the values of the two attributes are the same.

If this doesn't work, you can explicitly define which binding to use for the default HTTP endpoint by adding the <protocolMapping> element in your Web.config and adjust the binding configuration accordingly:

<protocolMapping>
    <add scheme="http" binding="basicHttpBinding"/>
</protocolMapping>
幸福丶如此 2025-01-13 12:22:43

为了举例说明我在评论中所说的内容,请在 web.config 的 部分中执行以下操作。

首先,在配置文件中指定绑定配置 - 例如:

<bindings>
  <wsHttpBinding>
    <binding name="MyWsHttpBinding" closeTimeout="00:05:00" 
             openTimeout="00:05:00" 
             receiveTimeout="00:05:00" 
             sendTimeout="00:05:00" 
             transactionFlow="false" 
             hostNameComparisonMode="StrongWildcard" 
             maxBufferPoolSize="524288" 
             maxReceivedMessageSize="5242880">
      <readerQuotas maxDepth="32" 
                    maxStringContentLength="5242880" 
                    maxArrayLength="16384" 
                    maxBytesPerRead="4096" 
                    maxNameTableCharCount="16384" />
    </binding>
  </wsHttpBinding>
</bindings>

接下来,您需要将上述配置分配给您的端点:

<services>
  <service behaviorConfiguration="MyServiceBehavior" name="MyService">
    <endpoint address="" 
              binding="wsHttpBinding" 
              bindingConfiguration="MyWsHttpBinding"
              contract="MyCompany.IMyService" />                       
  </service>
</services>

请务必记住通过 bindingConfiguration将绑定配置的名称分配给端点code>,否则您将获得所选绑定的默认值。

另外,请查看以下有关 WCF 4.0 的默认终结点和绑定的文章 - 开发人员简介Windows 通信基础 4

To give an example of what I was saying in my comment, do the following in the <system.serviceModel> section of your web.config.

First, specify a binding configuration in your config file - for example:

<bindings>
  <wsHttpBinding>
    <binding name="MyWsHttpBinding" closeTimeout="00:05:00" 
             openTimeout="00:05:00" 
             receiveTimeout="00:05:00" 
             sendTimeout="00:05:00" 
             transactionFlow="false" 
             hostNameComparisonMode="StrongWildcard" 
             maxBufferPoolSize="524288" 
             maxReceivedMessageSize="5242880">
      <readerQuotas maxDepth="32" 
                    maxStringContentLength="5242880" 
                    maxArrayLength="16384" 
                    maxBytesPerRead="4096" 
                    maxNameTableCharCount="16384" />
    </binding>
  </wsHttpBinding>
</bindings>

Next, you need to assign the above configuration to your endpoint:

<services>
  <service behaviorConfiguration="MyServiceBehavior" name="MyService">
    <endpoint address="" 
              binding="wsHttpBinding" 
              bindingConfiguration="MyWsHttpBinding"
              contract="MyCompany.IMyService" />                       
  </service>
</services>

It's important to remember to assign the name of the binding configuration to the endpoint via the bindingConfiguration, otherwise you'll get the default values for the selected binding.

Also, check out the following article regarding default endpoints and bindings for WCF 4.0 - A Developer's Introduction to Windows Communication Foundation 4

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文