0

I have developed WCF windows service using net tcp binding. Its working fine when wcf client and wcf service both are in domain (in two different system)

Getting error when both system are in work group not in domain.

Throwing an exception. Source: System.ServiceModel 4.0.0.0. Exception details: System.ServiceModel.CommunicationException: 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 '04:59:59.7955781'. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

Things I tried:

  • Turned off Firewalls
  • Checked port
  • Increased the timeouts
user173092
  • 127
  • 1
  • 1
  • 9
  • My first thought is to check and ensure both the client and server are supporting the same versions of TLS. This post may help, in particular John Wu's answer... https://stackoverflow.com/questions/45382254/update-net-web-service-to-use-tls-1-2#45442874 – quaabaam Aug 10 '20 at 20:44
  • Hi,has the problem been solved? – Ding Peng Aug 12 '20 at 02:05
  • No the problem hasn't been solved yet – user173092 Aug 12 '20 at 13:15

1 Answers1

0

First, you need to add windows credentials when requesting because nettcpbinding defaults to windows authentication:

    ServiceReference1.CalculatorClient calculatorClient = new ServiceReference1.CalculatorClient();
   calculatorClient.ClientCredentials.Windows.ClientCredential.UserName = "Administrator";
   calculatorClient.ClientCredentials.Windows.ClientCredential.Password = "Password";

If you still have problems after adding credentials, you also need to add a mex endpoint:

    <endpoint address="mex"
    binding="mexTcpBinding"
    contract="IMetadataExchange"></endpoint>

This is my App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
    </startup>

    <system.serviceModel>
        <services>
            <service name="ConsoleApp5.CalculatorService" behaviorConfiguration="ServiceBehavior">
                <host>
                    <baseAddresses>
                        <add baseAddress="net.tcp://localhost:10234/GettingStarted/"/>
                    </baseAddresses>
                </host>
                <endpoint address="Test"
                          binding="netTcpBinding"
                          contract="ConsoleApp5.ICalculator"/>
                <endpoint address="mex"
                          binding="mexTcpBinding"
                          contract="IMetadataExchange"></endpoint>
            </service>
        </services>


        <behaviors>
            <serviceBehaviors>
                <behavior name="ServiceBehavior">
                    <serviceMetadata/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>

</configuration>

UPDATE

Set the Mode value to Message:

<binding name="Binding">
          <security mode="Message">
            <message clientCredentialType="Certificate" />
          </security>
        </binding>

This is my App.config:

<?xml version="1.0"?>
<configuration>

  <system.serviceModel>
    <services>
      <service name="Microsoft.Samples.X509CertificateValidator.CalculatorService" behaviorConfiguration="CalculatorServiceBehavior">
        <!-- use host/baseAddresses to configure base address provided by host -->
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:8001/servicemodelsamples/service"/>
          </baseAddresses>
        </host>
        <!-- use base address specified above, provide one endpoint -->
        <endpoint address="certificate" binding="netTcpBinding" bindingConfiguration="Binding" contract="Microsoft.Samples.X509CertificateValidator.ICalculator"/>
         
      </service>
    </services>

    <bindings>
        <netTcpBinding>
        <!-- X509 certificate binding -->
        <binding name="Binding">
          <security mode="Message">
            <message clientCredentialType="Certificate" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>

    <behaviors>
        
      <serviceBehaviors>
        <behavior name="CalculatorServiceBehavior">
          <serviceDebug includeExceptionDetailInFaults="true"/>
            <serviceMetadata/>
          <serviceCredentials>
            <!-- 
            The serviceCredentials behavior allows one to specify authentication constraints on client certificates.
            -->
            <clientCertificate>
             
                <authentication certificateValidationMode="None" revocationMode="NoCheck"/>
            </clientCertificate>
            <!-- 
            The serviceCredentials behavior allows one to define a service certificate.
            A service certificate is used by a client to authenticate the service and provide message protection.
            This configuration references the "localhost" certificate installed during the setup instructions.
            -->
            <serviceCertificate findValue="localhost" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    
  </system.serviceModel>

<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

Feel free to let me know if the problem persists.

Ding Peng
  • 3,702
  • 1
  • 5
  • 8