wcf – 读取XML数据时已超出最大字符串内容长度配额(8192)

前端之家收集整理的这篇文章主要介绍了wcf – 读取XML数据时已超出最大字符串内容长度配额(8192)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图传递一个大字符串(24,000到50,000个字符)到自托管的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 – 服务器上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”不会意味着任何东西,除非配置文件中有一个绑定元素。这就是为什么你的服务不会开始,当你把它 – 你很可能有一些配置错误消息,我打赌。

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

>在配置文件中创建一个Binding元素,该元素具有您想要的maxStringContentLength的大小,并在name属性中为其指定名称
>在endpoint元素中,将名称从上面的步骤1分配给属性bindingConfiguration。

如果不为端点指定绑定配置,则服务将使用默认值。

例如,拿你的配置文件上面。在标记下,添加以下绑定配置(请注意,您使用的具体值和可选属性将根据服务的需要而有所不同):

<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”。

猜你在找的XML相关文章