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

发布于 2024-11-18 21:45:02 字数 5102 浏览 3 评论 0原文

我正在尝试将一个大字符串(24,000 到 50,000 个字符)传递给自托管 TCP WCF 服务。

我已将 maxStringContentLength (各处)提高到 22008192。

我在某处读到我需要将绑定配置更改为“LargeBuffer”或“LongFields”,但是当我这样做时:

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

或这样:

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

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

谢谢,

Jason

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>

我已经编辑了该服务(如下),但现在该服务无法启动。新的应用程序配置:

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

I'm trying to pass a large string (24,000 to 50,000 characters) to a self-hosted TCP WCF service.

I've upped the maxStringContentLength (everywhere) to 22008192.

I read somewhere that I need to change the bindingConfiguration to "LargeBuffer" or "LongFields" but when I do this:

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

or this:

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

My service won't start. I really need this error to go away. Any ideas?

Thanks,

Jason

PS -- config file from the tcp service on the server:

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

EDIT: Bindings as requested

    <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 Endpoints:

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

I've edited the service (as follows), but now the service won't start. The new 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>

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

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

发布评论

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

评论(2

长亭外,古道边 2024-11-25 21:45:02

bindingConfiguration 需要具有分配给 netTcpinding 元素的名称 - “LargeBuffer”或“LongFields”没有任何意义,除非配置文件中存在具有该名称的绑定元素。这就是为什么当你把它放进去时你的服务不会启动——我敢打赌,你很可能会收到某种配置错误消息。

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

  1. 在配置文件中创建一个具有所需 maxStringContentLength 大小的 Binding 元素,并在 name 属性中为其指定名称。
  2. 在端点元素中,将上面步骤 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"> 

EDITED TO ADD

Baed根据您的附加信息,在服务中的端点上为绑定配置属性分配值“NetTcpBinding_IService1”。

The bindingConfiguration needs to have the name you assign to the netTcpinding element - "LargeBuffer" or "LongFields" won't mean anything unless there is a binding element in the config file with that name. That is why your service won't start when you put that in - you most likely got a configuration error message of some sort, I bet.

To override the default 8192 setting for maxStringContentLength do this:

  1. Create a Binding element in the config file that has the size you want for maxStringContentLength and give it a name in the name attribute.
  2. In the endpoint element, assign the name from step 1 above to the attribute bindingConfiguration.

If you don't specify a binding configuration for the endpoint, the service will use the default values.

For example, take your config file above. Under the tag, add the following binding configuration (note that your specific values and the optional attributes you use will vary depending on the needs of your service):

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

Then when you define the endpoint:

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

EDITED TO ADD

Baed on your additional information, assing the bindingConfiguration attribute the value "NetTcpBinding_IService1" on the endpoint in your service.

写给空气的情书 2024-11-25 21:45:02

有时将“maxStringContentLength”值更改为最大值可能没有帮助。因此,在服务器配置文件的“basicHttpBinding”部分中添加以下“默认”绑定。

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

Sometimes changing "maxStringContentLength" value to maximum may not help.hence Add the below "default" binding inside the "basicHttpBinding" section in server config file.

          <binding >
            <readerQuotas maxDepth="32" maxStringContentLength="102400" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
          </binding>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文