需要进行更改以采用默认 web.config 并增加 maxStringContentLength
我需要将大量文本从我的一个客户端发送到我的服务器。为此,我知道我需要增加服务器上的 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>
背景信息:
- 中运行 Visual Studio 2010
- .NET 4
- 在 IIS 7
- VS
- 托管 VS 名为 Host.IIS WSDL URL = http://MyServer/Orders/OrdersService.svc?wsdl
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须修改服务端点上使用的绑定的属性。由于您没有在配置文件中提供任何内容,WCF 4.0 会自动添加每个服务合约的默认端点以及主机中定义的基地址。如果服务托管在 IIS 中,则基地址就是虚拟目录。
默认端点上使用的绑定在
元素中定义。在计算机级别,映射为:在您的情况下,除非默认映射已被覆盖,否则 WCF 使用 http://myserver/Orders 虚拟目录创建默认 HTTP 端点。 href="http://msdn.microsoft.com/en-us/library/ms731361.aspx" rel="nofollow">基本HttpBinding。
您可以修改 basicHttpBindingmaxStringContentLength 属性> 通过提供默认绑定配置,即无名配置,它将自动应用于使用该绑定的所有端点。
只需将此元素添加到 Web.config 的
部分即可:请注意 MSDN 建议 设置 maxStringContentLength 和 maxReceivedMessageSize 属性为相同的值:
如果这不起作用,您可以通过在 Web.config 中添加
元素来显式定义用于默认 HTTP 端点的绑定,并相应地调整绑定配置: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: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:Note that MSDN recommends to set both the maxStringContentLength and maxReceivedMessageSize properties to the same value:
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:为了举例说明我在评论中所说的内容,请在 web.config 的
部分中执行以下操作。首先,在配置文件中指定绑定配置 - 例如:
接下来,您需要将上述配置分配给您的端点:
请务必记住通过
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:
Next, you need to assign the above configuration to your endpoint:
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