29

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>

2 Answers2

37

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.

Tim
  • 28,212
  • 8
  • 63
  • 76
  • 1
    BTW, this is the same thing I said when you asked this question previously [here](http://stackoverflow.com/questions/6589770/passing-large-string-from-wcf-to-wcf-and-streamwriter) – Tim Jul 06 '11 at 17:33
  • Tried that, but now the service won't start. app.config added to my original post. Frustrating! –  Jul 06 '11 at 18:18
  • Does it give an error of any sort, or does it simply not start? – Tim Jul 06 '11 at 18:28
  • I get the "Service on Local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the Performance Logs and Alerts service." –  Jul 06 '11 at 18:34
  • 1
    I take it you're hosting the WCF service as a Windows Service? Check the Windows event log to see if any errors were logged. Beyond that, put some logging in your Windows service and write to the log as you pass certain steps (and any errors that are thrown) - it sounds like something is not working properly in your Windows service, and logging can help you narrow down the cause if there's nothing relevent in the windows event viewer (application logs). – Tim Jul 06 '11 at 18:50
  • 1
    Tim I have just one thing to say to you -- U da man!! Thanks a million! –  Jul 06 '11 at 22:33
  • Tim - This helped an insane amount. Thanks for providing that gem. – Captain Skyhawk Jan 07 '14 at 18:31
  • I was facing same issue on Windows Xp and Win7. with the solution provided above this got resolved on Win7 but on Windows XP issue still persist. Ant clu? – Kamlendra Sharma Oct 03 '16 at 07:24
  • 1
    @kamlendra - Are you trying to use net.tcp on Windows XP? IIRC (it's been a few years), XP doesn't support net.tcp binding because IIS 6.0 doesn't have WAS. See this [answer](http://stackoverflow.com/a/1030733/745969) as well. – Tim Oct 03 '16 at 15:35
0

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>
AdityaK
  • 29
  • 1
  • 9