0

I'm implementing WCF netTCPBinding and encountering a problem while running tasks related to the database. The exception is "System.Net.Sockets.SocketException: 'An existing connection was forcibly closed by the remote host' in net tcp binding". However, the behaviour is unpredictable sometimes it gives no exception and runs smoothly and sometimes it gives an exception.

I added service throttling, assigned maximum values to reader quota and buffer size but nothing worked for me. However, I unable to increase max connection value from 10 to other value because it gives an exception. I tried everything but nothing is working.

web.config

            <netTcpBinding>
                <binding name="IOperationsCenterService_server_TCP" closeTimeout="01:03:00" openTimeout="01:03:00" receiveTimeout="01:10:00" sendTimeout="01:10:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="1000" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10" maxReceivedMessageSize="2147483647">
                    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                    <reliableSession ordered="true" inactivityTimeout="10:00:00" enabled="false" />
                    <security mode="None">
                        <!--<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />-->
                    </security>
                </binding>
            </netTcpBinding>

         <behaviors>
            <serviceBehaviors>
                <behavior name="OpsCenter.ServiceApp.OperationsCenterServiceBehavior">
                    <serviceMetadata httpGetEnabled="false" />
                    <serviceThrottling maxConcurrentCalls="1000" maxConcurrentInstances="1000" maxConcurrentSessions="10000"/>
                    <serviceDebug includeExceptionDetailInFaults="true" />
                    <dataContractSerializer maxItemsInObjectGraph="2147483647" />
                </behavior>
            </serviceBehaviors>
        </behaviors>

            <service behaviorConfiguration="OpsCenter.ServiceApp.OperationsCenterServiceBehavior" name="OpsCenter.ServiceApp.OperationsCenterService">
                <identity>
                    <dns value="localhost" />
                </identity>
                <endpoint address="" binding="netTcpBinding"   contract="OpsCenter.ServiceApp.IOperationsCenterService">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
                <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
            </service>

App.config

           <netTcpBinding>
                <binding name="WSHttpBinding_IOperationsCenterService" closeTimeout="01:03:00" openTimeout="01:03:00" receiveTimeout="01:10:00" sendTimeout="01:10:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard"  listenBacklog="1000" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10" maxReceivedMessageSize="2147483647">
                    <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
                    <reliableSession ordered="true" inactivityTimeout="10:00:00" enabled="false"/>
                    <security mode="None">
                    </security>
                </binding>
            </netTcpBinding>

Please help I'm stuck here since Monday.

Note 1: The application runs perfectly well in visual studio debug mode. However, the problem occurred in release mode or when I installed an application on the client machine.

Faisal Sajjad
  • 239
  • 2
  • 4
  • 13

1 Answers1

0

How do you call the service, by Adding service reference or Channel Factory? After the service is deployed, can you test it by using WcfTestClient(type the service address and make a successful call)?
About WCFTestClient.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/wcf-test-client-wcftestclient-exe
I think there is something wrong with the service work state. Besides, please ensure that we have enabled windows features support for NetTcpBinding. enter image description here
enter image description here
Feel free to let me know if the problem still exists.

Abraham Qian
  • 7,117
  • 1
  • 8
  • 22
  • I'm calling the service by Channel Factory. However, the windows features you indicated me is already selected. In the code, I was using a Dictionary instead of List. By reverting back to list the problem solved. I don't know the dictionary has any impact on TCP connection state. – Faisal Sajjad Aug 16 '19 at 06:28
  • Either Dictionary or List type could be serialized and deserialized properly in WCF. the data contract namespace is necessary when we call the service with ChannelFactory. This will affect the identification of data types. Besides, although you have set the binding properties, you do not apply them to the service endpoint. Try to apply the binding configuration by using Bindingconfiguration property in the endpoint. – Abraham Qian Aug 16 '19 at 08:44
  • Actually, I'm using Dictionary in a business logic layer and that layer has nothing to do with request and response. I don't think so serialization and deserialization is really required. However, the rest of the changes I applied but the problem still remains the same when I use the Dictionary. – Faisal Sajjad Aug 17 '19 at 17:48