Self-hosted WCF can connect to localhost but can't connect remote












0















I have a self-hosted C# WCF .Net 4.6.1 Windows service that communicates with another self-hosted WCF service. This works fine when both services are on the same server. However, when I move the server to another computer, I get this error:




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. There are no firewalls running on either computer and I get a response when using http://192.168.1.129:6253/eTutorWcfService (using net.tcp in app).




Client app.config:



<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IeTutorMessage" />
</basicHttpBinding>
<netTcpBinding>
<binding name="NetTcpBinding_IeTutorMessage" />
</netTcpBinding>
</bindings>

<client>
<endpoint name="BasicHttpBinding_IeTutorMessage"
address="http://localhost:6253/eTutorWcfService"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IeTutorMessage"
contract="eTutorServiceReference.IeTutorMessage" />
<endpoint name="NetTcpBinding_IeTutorMessage"
address="net.tcp://localhost:6254/eTutorWcfService"
binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IeTutorMessage"
contract="eTutorServiceReference.IeTutorMessage" >
<identity>
<servicePrincipalName value = ""/>
</identity>
</endpoint>
</client>


Server app.config:



<services>
<service name="eTutorServer.eTutorWcfService"
behaviorConfiguration="myeTutorServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:6253/eTutorWcfService"/>
<add baseAddress="net.tcp://localhost:6254/eTutorWcfService"/>
</baseAddresses>
</host>
<endpoint
address="http://localhost:6253/eTutorWcfService"
binding="basicHttpBinding"
contract="eTutorServer.IeTutorMessage" />
<endpoint
address="net.tcp://localhost:6254/eTutorWcfService"
binding="netTcpBinding"
contract="eTutorServer.IeTutorMessage" />
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
<endpoint
address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="myeTutorServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>


The client code:



EndpointAddress address = new EndpointAddress("net.tcp://" + eTutorServiceIp + ":6254/eTutorWcfService");
eTutorServiceReference.IeTutorMessageClient client = new eTutorServiceReference.IeTutorMessageClient("NetTcpBinding_IeTutorMessage", address);

try
{
rtn = client.eTutorMessage(itm);
client.Close();
}


When the client tries to connect, the output window of the server shows an SecurityTokenValidationException but I'm not sure what to do about that or if it means something relevant. I'm sure this has something to do with security but I don't know what to add where.










share|improve this question

























  • Local host may be configured different on two PCs. Check host files : C:WindowsSystem32Driversetchosts

    – jdweng
    Jan 1 at 15:23











  • No entries in the hosts file on either computer.

    – Velocedge
    Jan 1 at 15:38













  • Use sniffer like wireshark or fiddler and compare results on working PC and non working PC. Look at http response status to see if you are getting 200 done. Also check the TCP to see if you are getting [FIN] which terminates a TCP connection indicating finish.

    – jdweng
    Jan 1 at 15:44











  • Maybe your entry <identity> <servicePrincipalName value = ""/> </identity> in the client config has to do with the SecruityTokenValidationException. I don't know, why it is in the config.

    – H.G. Sandhagen
    Jan 1 at 15:57











  • On the identity, it gets added automatically at some point with "msi/steve" (host name/user). I've taken out the value and the node but get the same error.

    – Velocedge
    Jan 1 at 17:18
















0















I have a self-hosted C# WCF .Net 4.6.1 Windows service that communicates with another self-hosted WCF service. This works fine when both services are on the same server. However, when I move the server to another computer, I get this error:




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. There are no firewalls running on either computer and I get a response when using http://192.168.1.129:6253/eTutorWcfService (using net.tcp in app).




Client app.config:



<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IeTutorMessage" />
</basicHttpBinding>
<netTcpBinding>
<binding name="NetTcpBinding_IeTutorMessage" />
</netTcpBinding>
</bindings>

<client>
<endpoint name="BasicHttpBinding_IeTutorMessage"
address="http://localhost:6253/eTutorWcfService"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IeTutorMessage"
contract="eTutorServiceReference.IeTutorMessage" />
<endpoint name="NetTcpBinding_IeTutorMessage"
address="net.tcp://localhost:6254/eTutorWcfService"
binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IeTutorMessage"
contract="eTutorServiceReference.IeTutorMessage" >
<identity>
<servicePrincipalName value = ""/>
</identity>
</endpoint>
</client>


Server app.config:



<services>
<service name="eTutorServer.eTutorWcfService"
behaviorConfiguration="myeTutorServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:6253/eTutorWcfService"/>
<add baseAddress="net.tcp://localhost:6254/eTutorWcfService"/>
</baseAddresses>
</host>
<endpoint
address="http://localhost:6253/eTutorWcfService"
binding="basicHttpBinding"
contract="eTutorServer.IeTutorMessage" />
<endpoint
address="net.tcp://localhost:6254/eTutorWcfService"
binding="netTcpBinding"
contract="eTutorServer.IeTutorMessage" />
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
<endpoint
address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="myeTutorServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>


The client code:



EndpointAddress address = new EndpointAddress("net.tcp://" + eTutorServiceIp + ":6254/eTutorWcfService");
eTutorServiceReference.IeTutorMessageClient client = new eTutorServiceReference.IeTutorMessageClient("NetTcpBinding_IeTutorMessage", address);

try
{
rtn = client.eTutorMessage(itm);
client.Close();
}


When the client tries to connect, the output window of the server shows an SecurityTokenValidationException but I'm not sure what to do about that or if it means something relevant. I'm sure this has something to do with security but I don't know what to add where.










share|improve this question

























  • Local host may be configured different on two PCs. Check host files : C:WindowsSystem32Driversetchosts

    – jdweng
    Jan 1 at 15:23











  • No entries in the hosts file on either computer.

    – Velocedge
    Jan 1 at 15:38













  • Use sniffer like wireshark or fiddler and compare results on working PC and non working PC. Look at http response status to see if you are getting 200 done. Also check the TCP to see if you are getting [FIN] which terminates a TCP connection indicating finish.

    – jdweng
    Jan 1 at 15:44











  • Maybe your entry <identity> <servicePrincipalName value = ""/> </identity> in the client config has to do with the SecruityTokenValidationException. I don't know, why it is in the config.

    – H.G. Sandhagen
    Jan 1 at 15:57











  • On the identity, it gets added automatically at some point with "msi/steve" (host name/user). I've taken out the value and the node but get the same error.

    – Velocedge
    Jan 1 at 17:18














0












0








0


0






I have a self-hosted C# WCF .Net 4.6.1 Windows service that communicates with another self-hosted WCF service. This works fine when both services are on the same server. However, when I move the server to another computer, I get this error:




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. There are no firewalls running on either computer and I get a response when using http://192.168.1.129:6253/eTutorWcfService (using net.tcp in app).




Client app.config:



<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IeTutorMessage" />
</basicHttpBinding>
<netTcpBinding>
<binding name="NetTcpBinding_IeTutorMessage" />
</netTcpBinding>
</bindings>

<client>
<endpoint name="BasicHttpBinding_IeTutorMessage"
address="http://localhost:6253/eTutorWcfService"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IeTutorMessage"
contract="eTutorServiceReference.IeTutorMessage" />
<endpoint name="NetTcpBinding_IeTutorMessage"
address="net.tcp://localhost:6254/eTutorWcfService"
binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IeTutorMessage"
contract="eTutorServiceReference.IeTutorMessage" >
<identity>
<servicePrincipalName value = ""/>
</identity>
</endpoint>
</client>


Server app.config:



<services>
<service name="eTutorServer.eTutorWcfService"
behaviorConfiguration="myeTutorServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:6253/eTutorWcfService"/>
<add baseAddress="net.tcp://localhost:6254/eTutorWcfService"/>
</baseAddresses>
</host>
<endpoint
address="http://localhost:6253/eTutorWcfService"
binding="basicHttpBinding"
contract="eTutorServer.IeTutorMessage" />
<endpoint
address="net.tcp://localhost:6254/eTutorWcfService"
binding="netTcpBinding"
contract="eTutorServer.IeTutorMessage" />
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
<endpoint
address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="myeTutorServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>


The client code:



EndpointAddress address = new EndpointAddress("net.tcp://" + eTutorServiceIp + ":6254/eTutorWcfService");
eTutorServiceReference.IeTutorMessageClient client = new eTutorServiceReference.IeTutorMessageClient("NetTcpBinding_IeTutorMessage", address);

try
{
rtn = client.eTutorMessage(itm);
client.Close();
}


When the client tries to connect, the output window of the server shows an SecurityTokenValidationException but I'm not sure what to do about that or if it means something relevant. I'm sure this has something to do with security but I don't know what to add where.










share|improve this question
















I have a self-hosted C# WCF .Net 4.6.1 Windows service that communicates with another self-hosted WCF service. This works fine when both services are on the same server. However, when I move the server to another computer, I get this error:




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. There are no firewalls running on either computer and I get a response when using http://192.168.1.129:6253/eTutorWcfService (using net.tcp in app).




Client app.config:



<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IeTutorMessage" />
</basicHttpBinding>
<netTcpBinding>
<binding name="NetTcpBinding_IeTutorMessage" />
</netTcpBinding>
</bindings>

<client>
<endpoint name="BasicHttpBinding_IeTutorMessage"
address="http://localhost:6253/eTutorWcfService"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IeTutorMessage"
contract="eTutorServiceReference.IeTutorMessage" />
<endpoint name="NetTcpBinding_IeTutorMessage"
address="net.tcp://localhost:6254/eTutorWcfService"
binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IeTutorMessage"
contract="eTutorServiceReference.IeTutorMessage" >
<identity>
<servicePrincipalName value = ""/>
</identity>
</endpoint>
</client>


Server app.config:



<services>
<service name="eTutorServer.eTutorWcfService"
behaviorConfiguration="myeTutorServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:6253/eTutorWcfService"/>
<add baseAddress="net.tcp://localhost:6254/eTutorWcfService"/>
</baseAddresses>
</host>
<endpoint
address="http://localhost:6253/eTutorWcfService"
binding="basicHttpBinding"
contract="eTutorServer.IeTutorMessage" />
<endpoint
address="net.tcp://localhost:6254/eTutorWcfService"
binding="netTcpBinding"
contract="eTutorServer.IeTutorMessage" />
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
<endpoint
address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="myeTutorServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>


The client code:



EndpointAddress address = new EndpointAddress("net.tcp://" + eTutorServiceIp + ":6254/eTutorWcfService");
eTutorServiceReference.IeTutorMessageClient client = new eTutorServiceReference.IeTutorMessageClient("NetTcpBinding_IeTutorMessage", address);

try
{
rtn = client.eTutorMessage(itm);
client.Close();
}


When the client tries to connect, the output window of the server shows an SecurityTokenValidationException but I'm not sure what to do about that or if it means something relevant. I'm sure this has something to do with security but I don't know what to add where.







c# wcf wcf-security self-host-webapi






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 16:48









marc_s

581k13011201267




581k13011201267










asked Jan 1 at 15:19









VelocedgeVelocedge

17312




17312













  • Local host may be configured different on two PCs. Check host files : C:WindowsSystem32Driversetchosts

    – jdweng
    Jan 1 at 15:23











  • No entries in the hosts file on either computer.

    – Velocedge
    Jan 1 at 15:38













  • Use sniffer like wireshark or fiddler and compare results on working PC and non working PC. Look at http response status to see if you are getting 200 done. Also check the TCP to see if you are getting [FIN] which terminates a TCP connection indicating finish.

    – jdweng
    Jan 1 at 15:44











  • Maybe your entry <identity> <servicePrincipalName value = ""/> </identity> in the client config has to do with the SecruityTokenValidationException. I don't know, why it is in the config.

    – H.G. Sandhagen
    Jan 1 at 15:57











  • On the identity, it gets added automatically at some point with "msi/steve" (host name/user). I've taken out the value and the node but get the same error.

    – Velocedge
    Jan 1 at 17:18



















  • Local host may be configured different on two PCs. Check host files : C:WindowsSystem32Driversetchosts

    – jdweng
    Jan 1 at 15:23











  • No entries in the hosts file on either computer.

    – Velocedge
    Jan 1 at 15:38













  • Use sniffer like wireshark or fiddler and compare results on working PC and non working PC. Look at http response status to see if you are getting 200 done. Also check the TCP to see if you are getting [FIN] which terminates a TCP connection indicating finish.

    – jdweng
    Jan 1 at 15:44











  • Maybe your entry <identity> <servicePrincipalName value = ""/> </identity> in the client config has to do with the SecruityTokenValidationException. I don't know, why it is in the config.

    – H.G. Sandhagen
    Jan 1 at 15:57











  • On the identity, it gets added automatically at some point with "msi/steve" (host name/user). I've taken out the value and the node but get the same error.

    – Velocedge
    Jan 1 at 17:18

















Local host may be configured different on two PCs. Check host files : C:WindowsSystem32Driversetchosts

– jdweng
Jan 1 at 15:23





Local host may be configured different on two PCs. Check host files : C:WindowsSystem32Driversetchosts

– jdweng
Jan 1 at 15:23













No entries in the hosts file on either computer.

– Velocedge
Jan 1 at 15:38







No entries in the hosts file on either computer.

– Velocedge
Jan 1 at 15:38















Use sniffer like wireshark or fiddler and compare results on working PC and non working PC. Look at http response status to see if you are getting 200 done. Also check the TCP to see if you are getting [FIN] which terminates a TCP connection indicating finish.

– jdweng
Jan 1 at 15:44





Use sniffer like wireshark or fiddler and compare results on working PC and non working PC. Look at http response status to see if you are getting 200 done. Also check the TCP to see if you are getting [FIN] which terminates a TCP connection indicating finish.

– jdweng
Jan 1 at 15:44













Maybe your entry <identity> <servicePrincipalName value = ""/> </identity> in the client config has to do with the SecruityTokenValidationException. I don't know, why it is in the config.

– H.G. Sandhagen
Jan 1 at 15:57





Maybe your entry <identity> <servicePrincipalName value = ""/> </identity> in the client config has to do with the SecruityTokenValidationException. I don't know, why it is in the config.

– H.G. Sandhagen
Jan 1 at 15:57













On the identity, it gets added automatically at some point with "msi/steve" (host name/user). I've taken out the value and the node but get the same error.

– Velocedge
Jan 1 at 17:18





On the identity, it gets added automatically at some point with "msi/steve" (host name/user). I've taken out the value and the node but get the same error.

– Velocedge
Jan 1 at 17:18












2 Answers
2






active

oldest

votes


















1














First, Nettcpbinding use transport security mode and authenticate the client with windows credential by default.
WCF throws exception that the server has rejected the client credentials, what is the default security mode for NetTCP in WCF

Then, when we change the server configuration and re-host the service, we should re-generate the client proxy class when we calling it. besides, we may need to change the endpoint address in the client configuration since Localhost is generated by default.




I can live with this but would really like to know how to do it
without security.




At last, when we change the security to None, the client does not need to provide the credentials to invoke the service. I suggest you re-host the service and re-generate the client proxy class. I have made a demo, wish it is useful to you.



Server end(console application)



class Program
{
static void Main(string args)
{
using (ServiceHost sh=new ServiceHost(typeof(MyService)))
{
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 IService
{
[OperationContract]
string SayHello();
}
public class MyService : IService
{
public string SayHello()
{
return "Hello Stranger";
}
}


App.config



<system.serviceModel>
<services>
<service behaviorConfiguration="Service1Behavior" name="VM1.MyService">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="mybinding" contract="VM1.IService" >
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:13007/"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="mybinding">
<security mode="None">
</security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="Service1Behavior">
<serviceMetadata />
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>


Client end.



ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();
try
{
Console.WriteLine(client.SayHello());
}
catch (Exception)
{

throw;
}


App.config



    <system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IService">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<client>
<!--we may need to change the generated endpoint address to autual server IP address.-->
<endpoint address="net.tcp://10.157.13.69:13007/" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IService" contract="ServiceReference1.IService"
name="NetTcpBinding_IService" />
</client>
</system.serviceModel>


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






share|improve this answer































    0














    I added the following code and it works:



    client.ClientCredentials.Windows.ClientCredential.UserName = runAs;
    client.ClientCredentials.Windows.ClientCredential.Password = runAsPassword;
    client.ClientCredentials.Windows.ClientCredential.Domain = runAsDomain;


    However, I'd like to do this without security since it will be placed on multiple servers, none of which will have a public IP. I've tried to add to the bindings but on the client it's not a valid node and on the server, it stops the service from starting. I tried to add the following code to the server but it won't open the ServiceHost:



    serviceHost.AddServiceEndpoint(typeof(eTutorWcfService), new NetTcpBinding(SecurityMode.None), "");


    I can live with this but would really like to know how to do it without security.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996600%2fself-hosted-wcf-can-connect-to-localhost-but-cant-connect-remote%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      First, Nettcpbinding use transport security mode and authenticate the client with windows credential by default.
      WCF throws exception that the server has rejected the client credentials, what is the default security mode for NetTCP in WCF

      Then, when we change the server configuration and re-host the service, we should re-generate the client proxy class when we calling it. besides, we may need to change the endpoint address in the client configuration since Localhost is generated by default.




      I can live with this but would really like to know how to do it
      without security.




      At last, when we change the security to None, the client does not need to provide the credentials to invoke the service. I suggest you re-host the service and re-generate the client proxy class. I have made a demo, wish it is useful to you.



      Server end(console application)



      class Program
      {
      static void Main(string args)
      {
      using (ServiceHost sh=new ServiceHost(typeof(MyService)))
      {
      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 IService
      {
      [OperationContract]
      string SayHello();
      }
      public class MyService : IService
      {
      public string SayHello()
      {
      return "Hello Stranger";
      }
      }


      App.config



      <system.serviceModel>
      <services>
      <service behaviorConfiguration="Service1Behavior" name="VM1.MyService">
      <endpoint address="" binding="netTcpBinding" bindingConfiguration="mybinding" contract="VM1.IService" >
      </endpoint>
      <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
      <host>
      <baseAddresses>
      <add baseAddress="net.tcp://localhost:13007/"/>
      </baseAddresses>
      </host>
      </service>
      </services>
      <bindings>
      <netTcpBinding>
      <binding name="mybinding">
      <security mode="None">
      </security>
      </binding>
      </netTcpBinding>
      </bindings>
      <behaviors>
      <serviceBehaviors>
      <behavior name="Service1Behavior">
      <serviceMetadata />
      <serviceDebug includeExceptionDetailInFaults="False"/>
      </behavior>
      </serviceBehaviors>
      </behaviors>
      </system.serviceModel>


      Client end.



      ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();
      try
      {
      Console.WriteLine(client.SayHello());
      }
      catch (Exception)
      {

      throw;
      }


      App.config



          <system.serviceModel>
      <bindings>
      <netTcpBinding>
      <binding name="NetTcpBinding_IService">
      <security mode="None" />
      </binding>
      </netTcpBinding>
      </bindings>
      <client>
      <!--we may need to change the generated endpoint address to autual server IP address.-->
      <endpoint address="net.tcp://10.157.13.69:13007/" binding="netTcpBinding"
      bindingConfiguration="NetTcpBinding_IService" contract="ServiceReference1.IService"
      name="NetTcpBinding_IService" />
      </client>
      </system.serviceModel>


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






      share|improve this answer




























        1














        First, Nettcpbinding use transport security mode and authenticate the client with windows credential by default.
        WCF throws exception that the server has rejected the client credentials, what is the default security mode for NetTCP in WCF

        Then, when we change the server configuration and re-host the service, we should re-generate the client proxy class when we calling it. besides, we may need to change the endpoint address in the client configuration since Localhost is generated by default.




        I can live with this but would really like to know how to do it
        without security.




        At last, when we change the security to None, the client does not need to provide the credentials to invoke the service. I suggest you re-host the service and re-generate the client proxy class. I have made a demo, wish it is useful to you.



        Server end(console application)



        class Program
        {
        static void Main(string args)
        {
        using (ServiceHost sh=new ServiceHost(typeof(MyService)))
        {
        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 IService
        {
        [OperationContract]
        string SayHello();
        }
        public class MyService : IService
        {
        public string SayHello()
        {
        return "Hello Stranger";
        }
        }


        App.config



        <system.serviceModel>
        <services>
        <service behaviorConfiguration="Service1Behavior" name="VM1.MyService">
        <endpoint address="" binding="netTcpBinding" bindingConfiguration="mybinding" contract="VM1.IService" >
        </endpoint>
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
        <host>
        <baseAddresses>
        <add baseAddress="net.tcp://localhost:13007/"/>
        </baseAddresses>
        </host>
        </service>
        </services>
        <bindings>
        <netTcpBinding>
        <binding name="mybinding">
        <security mode="None">
        </security>
        </binding>
        </netTcpBinding>
        </bindings>
        <behaviors>
        <serviceBehaviors>
        <behavior name="Service1Behavior">
        <serviceMetadata />
        <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
        </serviceBehaviors>
        </behaviors>
        </system.serviceModel>


        Client end.



        ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();
        try
        {
        Console.WriteLine(client.SayHello());
        }
        catch (Exception)
        {

        throw;
        }


        App.config



            <system.serviceModel>
        <bindings>
        <netTcpBinding>
        <binding name="NetTcpBinding_IService">
        <security mode="None" />
        </binding>
        </netTcpBinding>
        </bindings>
        <client>
        <!--we may need to change the generated endpoint address to autual server IP address.-->
        <endpoint address="net.tcp://10.157.13.69:13007/" binding="netTcpBinding"
        bindingConfiguration="NetTcpBinding_IService" contract="ServiceReference1.IService"
        name="NetTcpBinding_IService" />
        </client>
        </system.serviceModel>


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






        share|improve this answer


























          1












          1








          1







          First, Nettcpbinding use transport security mode and authenticate the client with windows credential by default.
          WCF throws exception that the server has rejected the client credentials, what is the default security mode for NetTCP in WCF

          Then, when we change the server configuration and re-host the service, we should re-generate the client proxy class when we calling it. besides, we may need to change the endpoint address in the client configuration since Localhost is generated by default.




          I can live with this but would really like to know how to do it
          without security.




          At last, when we change the security to None, the client does not need to provide the credentials to invoke the service. I suggest you re-host the service and re-generate the client proxy class. I have made a demo, wish it is useful to you.



          Server end(console application)



          class Program
          {
          static void Main(string args)
          {
          using (ServiceHost sh=new ServiceHost(typeof(MyService)))
          {
          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 IService
          {
          [OperationContract]
          string SayHello();
          }
          public class MyService : IService
          {
          public string SayHello()
          {
          return "Hello Stranger";
          }
          }


          App.config



          <system.serviceModel>
          <services>
          <service behaviorConfiguration="Service1Behavior" name="VM1.MyService">
          <endpoint address="" binding="netTcpBinding" bindingConfiguration="mybinding" contract="VM1.IService" >
          </endpoint>
          <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
          <host>
          <baseAddresses>
          <add baseAddress="net.tcp://localhost:13007/"/>
          </baseAddresses>
          </host>
          </service>
          </services>
          <bindings>
          <netTcpBinding>
          <binding name="mybinding">
          <security mode="None">
          </security>
          </binding>
          </netTcpBinding>
          </bindings>
          <behaviors>
          <serviceBehaviors>
          <behavior name="Service1Behavior">
          <serviceMetadata />
          <serviceDebug includeExceptionDetailInFaults="False"/>
          </behavior>
          </serviceBehaviors>
          </behaviors>
          </system.serviceModel>


          Client end.



          ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();
          try
          {
          Console.WriteLine(client.SayHello());
          }
          catch (Exception)
          {

          throw;
          }


          App.config



              <system.serviceModel>
          <bindings>
          <netTcpBinding>
          <binding name="NetTcpBinding_IService">
          <security mode="None" />
          </binding>
          </netTcpBinding>
          </bindings>
          <client>
          <!--we may need to change the generated endpoint address to autual server IP address.-->
          <endpoint address="net.tcp://10.157.13.69:13007/" binding="netTcpBinding"
          bindingConfiguration="NetTcpBinding_IService" contract="ServiceReference1.IService"
          name="NetTcpBinding_IService" />
          </client>
          </system.serviceModel>


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






          share|improve this answer













          First, Nettcpbinding use transport security mode and authenticate the client with windows credential by default.
          WCF throws exception that the server has rejected the client credentials, what is the default security mode for NetTCP in WCF

          Then, when we change the server configuration and re-host the service, we should re-generate the client proxy class when we calling it. besides, we may need to change the endpoint address in the client configuration since Localhost is generated by default.




          I can live with this but would really like to know how to do it
          without security.




          At last, when we change the security to None, the client does not need to provide the credentials to invoke the service. I suggest you re-host the service and re-generate the client proxy class. I have made a demo, wish it is useful to you.



          Server end(console application)



          class Program
          {
          static void Main(string args)
          {
          using (ServiceHost sh=new ServiceHost(typeof(MyService)))
          {
          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 IService
          {
          [OperationContract]
          string SayHello();
          }
          public class MyService : IService
          {
          public string SayHello()
          {
          return "Hello Stranger";
          }
          }


          App.config



          <system.serviceModel>
          <services>
          <service behaviorConfiguration="Service1Behavior" name="VM1.MyService">
          <endpoint address="" binding="netTcpBinding" bindingConfiguration="mybinding" contract="VM1.IService" >
          </endpoint>
          <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
          <host>
          <baseAddresses>
          <add baseAddress="net.tcp://localhost:13007/"/>
          </baseAddresses>
          </host>
          </service>
          </services>
          <bindings>
          <netTcpBinding>
          <binding name="mybinding">
          <security mode="None">
          </security>
          </binding>
          </netTcpBinding>
          </bindings>
          <behaviors>
          <serviceBehaviors>
          <behavior name="Service1Behavior">
          <serviceMetadata />
          <serviceDebug includeExceptionDetailInFaults="False"/>
          </behavior>
          </serviceBehaviors>
          </behaviors>
          </system.serviceModel>


          Client end.



          ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();
          try
          {
          Console.WriteLine(client.SayHello());
          }
          catch (Exception)
          {

          throw;
          }


          App.config



              <system.serviceModel>
          <bindings>
          <netTcpBinding>
          <binding name="NetTcpBinding_IService">
          <security mode="None" />
          </binding>
          </netTcpBinding>
          </bindings>
          <client>
          <!--we may need to change the generated endpoint address to autual server IP address.-->
          <endpoint address="net.tcp://10.157.13.69:13007/" binding="netTcpBinding"
          bindingConfiguration="NetTcpBinding_IService" contract="ServiceReference1.IService"
          name="NetTcpBinding_IService" />
          </client>
          </system.serviceModel>


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







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 7 at 2:36









          Abraham QianAbraham Qian

          881117




          881117

























              0














              I added the following code and it works:



              client.ClientCredentials.Windows.ClientCredential.UserName = runAs;
              client.ClientCredentials.Windows.ClientCredential.Password = runAsPassword;
              client.ClientCredentials.Windows.ClientCredential.Domain = runAsDomain;


              However, I'd like to do this without security since it will be placed on multiple servers, none of which will have a public IP. I've tried to add to the bindings but on the client it's not a valid node and on the server, it stops the service from starting. I tried to add the following code to the server but it won't open the ServiceHost:



              serviceHost.AddServiceEndpoint(typeof(eTutorWcfService), new NetTcpBinding(SecurityMode.None), "");


              I can live with this but would really like to know how to do it without security.






              share|improve this answer




























                0














                I added the following code and it works:



                client.ClientCredentials.Windows.ClientCredential.UserName = runAs;
                client.ClientCredentials.Windows.ClientCredential.Password = runAsPassword;
                client.ClientCredentials.Windows.ClientCredential.Domain = runAsDomain;


                However, I'd like to do this without security since it will be placed on multiple servers, none of which will have a public IP. I've tried to add to the bindings but on the client it's not a valid node and on the server, it stops the service from starting. I tried to add the following code to the server but it won't open the ServiceHost:



                serviceHost.AddServiceEndpoint(typeof(eTutorWcfService), new NetTcpBinding(SecurityMode.None), "");


                I can live with this but would really like to know how to do it without security.






                share|improve this answer


























                  0












                  0








                  0







                  I added the following code and it works:



                  client.ClientCredentials.Windows.ClientCredential.UserName = runAs;
                  client.ClientCredentials.Windows.ClientCredential.Password = runAsPassword;
                  client.ClientCredentials.Windows.ClientCredential.Domain = runAsDomain;


                  However, I'd like to do this without security since it will be placed on multiple servers, none of which will have a public IP. I've tried to add to the bindings but on the client it's not a valid node and on the server, it stops the service from starting. I tried to add the following code to the server but it won't open the ServiceHost:



                  serviceHost.AddServiceEndpoint(typeof(eTutorWcfService), new NetTcpBinding(SecurityMode.None), "");


                  I can live with this but would really like to know how to do it without security.






                  share|improve this answer













                  I added the following code and it works:



                  client.ClientCredentials.Windows.ClientCredential.UserName = runAs;
                  client.ClientCredentials.Windows.ClientCredential.Password = runAsPassword;
                  client.ClientCredentials.Windows.ClientCredential.Domain = runAsDomain;


                  However, I'd like to do this without security since it will be placed on multiple servers, none of which will have a public IP. I've tried to add to the bindings but on the client it's not a valid node and on the server, it stops the service from starting. I tried to add the following code to the server but it won't open the ServiceHost:



                  serviceHost.AddServiceEndpoint(typeof(eTutorWcfService), new NetTcpBinding(SecurityMode.None), "");


                  I can live with this but would really like to know how to do it without security.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 2 at 13:43









                  VelocedgeVelocedge

                  17312




                  17312






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996600%2fself-hosted-wcf-can-connect-to-localhost-but-cant-connect-remote%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      MongoDB - Not Authorized To Execute Command

                      How to fix TextFormField cause rebuild widget in Flutter

                      in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith