none
WCF using nettcp binding trying to consume a workflow service hosted using workflowservicehost using nettcpbinding RRS feed

  • Question

  • Hi,

    I have an issue in which i have a wcf service which call a workflowservice hosted using workflowservicehost.

    the code for the workflowservicehost is as follows

    app.config

      <bindings>
          <netTcpBinding>
            <binding name="tcpBinding" receiveTimeout="00:15:00" sendTimeout="00:15:00"  maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
              <security mode="None">
              </security>
            </binding>
          </netTcpBinding>
          <wsHttpBinding>
            <binding name="WorkflowControlHttpsBinding" transactionFlow="true">
              <security mode="Transport"/>
            </binding>
            <binding name="WorkflowControlHttpBinding" transactionFlow="true"/>
          </wsHttpBinding>
        </bindings>

    c# code

                                                                   

    SqlWorkflowInstanceStoreBehavior instanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior(persistenceConnectionString);
                    instanceStoreBehavior.InstanceCompletionAction = InstanceCompletionAction.DeleteAll;
                    instanceStoreBehavior.InstanceEncodingOption = InstanceEncodingOption.GZip;
                    instanceStoreBehavior.InstanceLockedExceptionAction = InstanceLockedExceptionAction.AggressiveRetry;
                    serviceHost.Description.Behaviors.Add(instanceStoreBehavior);
                    serviceHost.Description.Behaviors.Add(new WorkflowIdleBehavior() { TimeToPersist = new TimeSpan(0),TimeToUnload = new TimeSpan(0) });
                    serviceHost.Description.Behaviors.Add(new WorkflowUnhandledExceptionBehavior() { Action= WorkflowUnhandledExceptionAction.AbandonAndSuspend });
                    serviceHost.UnknownMessageReceived += new EventHandler<System.ServiceModel.UnknownMessageReceivedEventArgs>(EmBankWorkflowService.UnknownMessageReceive);
                    // add the control endpoint
                    NetTcpBinding nettcpbinding = new NetTcpBinding("tcpBinding");//Here we call the app.config

                    //nettcpbinding.PortSharingEnabled = true;
                    //nettcpbinding.ReceiveTimeout = new TimeSpan(0, 15, 0);
                    //nettcpbinding.SendTimeout = new TimeSpan(0, 15, 0);
                    //nettcpbinding.MaxBufferPoolSize = int.MaxValue;
                    //nettcpbinding.MaxBufferSize = int.MaxValue;

                    //nettcpbinding.MaxReceivedMessageSize = int.MaxValue;
                    //nettcpbinding.ReaderQuotas.MaxArrayLength = int.MaxValue;
                    //nettcpbinding.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
                    //nettcpbinding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
                    //nettcpbinding.ReaderQuotas.MaxDepth = int.MaxValue;
                    //nettcpbinding.ReaderQuotas.MaxNameTableCharCount = int.MaxValue;

                    WorkflowControlEndpoint publicEndpoint = new WorkflowControlEndpoint(
                                                                nettcpbinding,//  new BasicHttpBinding(),
                                                                    new EndpointAddress(new Uri(EndPoints.GetValue(j).ToString())));

                    //ServiceBehaviorAttribute sba = serviceHost.Description.Behaviors.Find<ServiceBehaviorAttribute>();
                    //if (sba == null)
                    //{
                    //    sba = new ServiceBehaviorAttribute();
                    //    sba.MaxItemsInObjectGraph = int.MaxValue;
                    //    serviceHost.Description.Behaviors.Add(sba);
                    //}

                    serviceHost.AddServiceEndpoint(publicEndpoint);
                    serviceHost.AddDefaultEndpoints();
                    serviceHost.Faulted += ServiceHost_Faulted;
                    serviceHost.Closed += ServiceHost_Closed;



                    //
                    serviceHost.Open();

    When i call this service from a WCF service I receive the following error

    ype : System.Net.Sockets.SocketException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    Message : An existing connection was forcibly closed by the remote host
    Source : System
    Help link : 
    ErrorCode : 10054
    SocketErrorCode : ConnectionReset
    NativeErrorCode : 10054
    Data : System.Collections.ListDictionaryInternal
    TargetSite : Int32 Receive(Byte[], Int32, Int32, System.Net.Sockets.SocketFlags)
    HResult : -2147467259
    Stack Trace :    at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
       at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)

    Message: HandlingInstanceID: ce328134-87ea-49f0-8bed-7292bb6d2f02
    An exception of type 'System.ServiceModel.CommunicationException' occurred and was caught.
    ------------------------------------------------------------------------------------------
    10/26/2019 23:14:59
    Type : System.ServiceModel.CommunicationException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    Message : The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:14:59.9960108'.
    Source : mscorlib
    Help link : 
    Data : System.Collections.ListDictionaryInternal
    TargetSite : Void HandleReturnMessage(System.Runtime.Remoting.Messaging.IMessage, System.Runtime.Remoting.Messaging.IMessage)
    HResult : -2146233087
    Stack Trace : 
    Server stack trace: 
       at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
       at System.ServiceModel.Channels.SocketConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
       at System.ServiceModel.Channels.DelegatingConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
       at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.SendPreamble(IConnection connection, ArraySegment`1 preamble, TimeoutHelper& timeoutHelper)
       at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.DuplexConnectionPoolHelper.AcceptPooledConnection(IConnection connection, TimeoutHelper& timeoutHelper)
       at System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)
       at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

    Please help as I am literally stuck with this issue. I tried wcf tracing but still receiving the same error.

    Thanks in advance

    Regards,

    Bobby

    Saturday, October 26, 2019 6:10 PM

All replies

  • how do you develop your client-side code?
    Please ensure the below window features is enable and the service is on the running state on the server-side.
    https://i.stack.imgur.com/ZsE8K.png

    https://i.stack.imgur.com/HfG5i.png
    At last, please refer to my example.
    Server-side(Console application).

        class Program
        {
     
            /// <param name="args"></param>
            static void Main(string[] args)
            {
                using (ServiceHost sh = new ServiceHost(typeof(TestService)))
                {
                    sh.Opened += delegate
                    {
                        Console.WriteLine("service is ready");
                    };
    
                    sh.Closed += delegate
                    {
                        Console.WriteLine("service is closed");
                    };
                    sh.Open();
    
                Console.ReadLine();
                sh.Close();
            }
        }
        }
        [ServiceContract]
        public interface ITestService
        {
            [OperationContract]
            string GetResult();
        }
    
        [ServiceBehavior]
        public class TestService : ITestService
        {
            public string GetResult()
            {
                return DateTime.Now.ToLongTimeString();
            }
        }
    

    Appconfig(server-side).

    <system.serviceModel>
        <services>
          <service  name="ConsoleApp3.TestService">
            <endpoint address="" binding="netTcpBinding" contract="ConsoleApp3.ITestService" bindingConfiguration="mybinding"></endpoint>
            <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"></endpoint>
            <host>
              <baseAddresses>
                <add baseAddress="net.tcp://localhost:16666"/>
              </baseAddresses>
            </host>
          </service>
        </services>
        <bindings>
          <netTcpBinding>
            <binding name="mybinding">
              <security mode="None"></security>
            </binding>
          </netTcpBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata />
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    

      

    Client-side (Console application, configuration is automatically generated by adding service reference).

     ServiceReference1.TestServiceClient client = new ServiceReference1.TestServiceClient();
                try
                {
                    var result = client.GetResult();
                    Console.WriteLine(result);
                }
                catch (Exception)
                {
                    throw;
                }
                client.Close();

     


    Appconfig(client-side). please pay attention to the service address, by default it is Localhost.

      <system.serviceModel>
            <bindings>
                <netTcpBinding>
                    <binding name="NetTcpBinding_ITestService">
                        <security mode="None">
                            <transport sslProtocols="None" />
                        </security>
                    </binding>
                </netTcpBinding>
            </bindings>
            <client>
                <endpoint address="net.tcp://10.157.13.69:16666/" binding="netTcpBinding"
                    bindingConfiguration="NetTcpBinding_ITestService" contract="ServiceReference1.ITestService"
                    name="NetTcpBinding_ITestService" />
            </client>
    </system.serviceModel>
    

    Feel free to let me know if there is anything I can help with.

    Best Regards

    Abraham

    Tuesday, October 29, 2019 11:09 AM
    Moderator