读取XML数据时,超过了最大string内容长度限额(8192)

我试图传递一个大的string(24,000到50,000个字符)到一个自托pipe的TCP WCF服务。

我已经把maxStringContentLength(无处不在)设置为22008192。

我读了一些地方,我需要将bindingConfiguration更改为“LargeBuffer”或“LongFields”,但是当我这样做:

<endpoint address="" binding="netTcpBinding" bindingConfiguration="LongFields" contract="ExStreamWCF.IService1"> 

或这个:

 <endpoint address="" binding="netTcpBinding" bindingConfiguration="LargeBuffer" contract="ExStreamWCF.IService1"> 

我的服务无法启动。 我真的需要这个错误消失。 有任何想法吗?

谢谢,

贾森

PS-config文件从服务器上的tcp服务:

 <system.serviceModel> <services> <service behaviorConfiguration="ExStreamWCF.Service1Behavior" name="ExStreamWCF.Service1"> <endpoint address="" binding="netTcpBinding" bindingConfiguration="" contract="ExStreamWCF.IService1"> <identity> <dns value="Devexstream-2.anchorgeneral.local" /> <!--<dns value="vmwin2k3sta-tn2" />--> </identity> </endpoint> <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="net.tcp://Devexstream-2:8080/Service" /> <!--<add baseAddress="net.tcp://vmwin2k3sta-tn2:8080/Service" />--> </baseAddresses> </host> </service> </services> <behaviors> <serviceBehaviors> <behavior name="ExStreamWCF.Service1Behavior"> <serviceMetadata httpGetEnabled="false" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> </behaviors> 

编辑:绑定按要求

  <system.serviceModel> <bindings> <netTcpBinding> <binding name="NetTcpBinding_IService1" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288" maxBufferSize="2565536" maxConnections="10" maxReceivedMessageSize="2565536"> <readerQuotas maxDepth="22008192" maxStringContentLength="22008192" maxArrayLength="2516384" maxBytesPerRead="22008192" maxNameTableCharCount="22008192" /> <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" /> <security mode="Transport"> <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" /> <message clientCredentialType="Windows" /> </security> </binding> </netTcpBinding> </bindings> 

客户端点:

 <client> <endpoint address="net.tcp://devexstream-2:8080/Service" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IService1" contract="TCPService.IService1" name="NetTcpBinding_IService1"> <identity> <servicePrincipalName value="TCPService\Devexstream-2" /> <dns value="Devexstream-2.anchorgeneral.local" /> </identity> </endpoint> 

我编辑了服务(如下),但现在服务不会启动。 新的app.config:

 <system.serviceModel> <bindings> <netTcpBinding> <binding name="ExStreamWCFBinding" closeTimeout="00:00:05" openTimeout="00:00:05" receiveTimeout="00:00:05" sendTimeout="00:00:05" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparison="StrongWildCard" maxBufferPoolSize="524288" maxBufferSize="524288" maxConnections="10" maxReceivedMessageSize="5242880"> <readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> </binding> </netTcpBinding> </bindings> <services> <service behaviorConfiguration="ExStreamWCF.Service1Behavior" name="ExStreamWCF.Service1"> <endpoint address="" binding="netTcpBinding" bindingConfiguration="ExStreamWCFBinding" contract="ExStreamWCF.IService1"> <identity> <dns value="Devexstream-2.anchorgeneral.local" /> <!--<dns value="vmwin2k3sta-tn2" />--> </identity> </endpoint> <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="net.tcp://Devexstream-2:8080/Service" /> <!--<add baseAddress="net.tcp://vmwin2k3sta-tn2:8080/Service" />--> </baseAddresses> </host> </service> </services> <behaviors> <serviceBehaviors> <behavior name="ExStreamWCF.Service1Behavior"> <serviceMetadata httpGetEnabled="false" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> </behaviors> 

bindingConfiguration需要有分配给netTcpinding元素的名字 – “LargeBuffer”或“LongFields”不会代表任何东西,除非在configuration文件中有这个名字的绑定元素。 这就是为什么当你把服务放进去的时候你的服务不会启动的原因 – 你可能会得到某种configuration错误信息,我敢打赌。

要覆盖maxStringContentLength的默认8192设置,请执行以下操作:

  1. 在configuration文件中创build一个具有maxStringContentLength所需大小的Binding元素,并在name属性中为其指定一个名称。
  2. 在endpoint元素中,将上述步骤1中的名称分配给bindingConfiguration属性。

如果您没有为端点指定绑定configuration,则该服务将使用默认值。

例如,把你的configuration文件放在上面。 在标签下添加以下绑定configuration(注意,您使用的特定值和可选属性将根据您的服务需求而有所不同):

 <bindings> <netTcpBinding> <binding name="ExStreamWCFBinding" closeTimeout="00:00:05" openTimeout="00:00:05" receiveTimeout="00:00:05" sendTimeout="00:00:05" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparison="StrongWildCard" maxBufferPoolSize="524288" maxBufferSize="524288" maxConnections="10" maxReceivedMessageSize="5242880"> <readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> </binding> </netTcpBinding> </bindings> 

那么当你定义端点时:

 <endpoint address="" binding="netTcpBinding" bindingConfiguration="ExStreamWCFBinding" contract="ExStreamWCF.IService1"> 

编辑添加

根据您的附加信息,在您的服务的端点上绑定bindingConfiguration属性的值“NetTcpBinding_IService1”。

有时将“maxStringContentLength”值更改为最大值可能无济于事。在服务器configuration文件的“basicHttpBinding”部分中添加下面的“默认”绑定。

  <binding > <readerQuotas maxDepth="32" maxStringContentLength="102400" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> </binding>