none
WCF Assistance needed : Setting up base address for tcp binding between remote PC's on the same network RRS feed

  • Question

  • I am having a problem connecting to a WCF Host service running on a remote pc on my home network.  I performed the following. 

    I retrieved  my remote pc's full domain name from control panel. It was listed as ROBIN-PC. I used this name as my address "MachineName" in the address portion of the server and client config files. From my client PC I ran a ping test to the remote ROBIN-PC running the WCF Host program to verify a communication response.
    I executed the host service on my remote pc then opened a separate command prompt to validate that the service was listening on port 8090. (netstat -an)

    On the remote PC, The file containing The Host service (MagicEightBallService) is running as a console application from location C:\TestService\Host.


    My client config contains the following:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <system.serviceModel>
            <client>
                <endpoint address="net.tcp://ROBIN-PC:8090/TestService/Host/MagicEightBallService"
                    binding="netTcpBinding"
                    contract="ServiceReference1.IEightBall" 
                    name="netTcpBinding_IEightBall" />
            </client>
        </system.serviceModel>
    </configuration>


     
     My server config is setup as:
     
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <system.serviceModel>
          <services>
            <service name ="MagicEightBallServiceLib2.MagicEightBallService">
              <endpoint address=""
                        binding="netTcpBinding"
                        contract="MagicEightBallServiceLib2.IEightBall"/>
              <!--Need to add this so Mex knows address of the service-->
              <host>
                <baseAddresses>
                  <add baseAddress="net.tcp://ROBIN-PC:8090/TestService/Host/MagicEightBallService"/>
                </baseAddresses>
              </host>
            </service>
          </services>
        </system.serviceModel>
    </configuration>




    Although the  Host Server is receptive and responsive if both server and client are running on the same
    machine, the server does not recieve the messages when I run the host and client on separate pc's
    on the same network. 

    I also tried the following explicit addressing in the client config

    <address="net.tcp://192.168.1.19:8090/TestService/Host/MagicEightBallService"/>

    Can anyone tell me What I am missing?







    • Edited by NYBruce Tuesday, July 12, 2016 1:48 AM
    Tuesday, July 12, 2016 1:46 AM

Answers

  • Edward,

    Thanks for getting me over the first part of my hurdle. While building a client app on a localhost or remote pc , AddServiceReference now allows me to discover service information using  the net.tcp base address. I just needed to enable mex.  I thought this was only done when binding = basicHttpbinding.  Is it true that regardless of whether you use http/net.tcp that mex must be enabled for discovery?   Is it necessary to also have an http address along with the net.tcp address in the <baseaddress> setting during Discovery time? 

    My current issue is that the client and server communicate well on the localhost pc , but not when I move the client to a remote pc.  I was able to  discover the service on the remote pc  when I built the client/proxy app using AddServiceReferene. But, when I run the client from the remote I get a SecurityNegotiationException. The detail says that the server has rejected the client credentials.  I tried fiddling around with the security binding in both config files and I'm not quite coming up with the right combination to allow communication.

    My clientr config

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
           <system.serviceModel>
            <bindings>
                <netTcpBinding>
                    <binding name="NetTcpBinding_IEightBall" />
                    <!--<binding name = "tcpUnsecured ">
                       <security mode = "Transport"/>  //also tried "None"
                      <transport clientCredentialType="Windows" />
                    </binding>-->
                </netTcpBinding>
            </bindings>
            <client>
                <endpoint address="net.tcp://develop2:8090/MagicEightBallService"
                    binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IEightBall"
                    contract="ServiceReference1.IEightBall" name="NetTcpBinding_IEightBall">
                    <!-- <identity>
                        <userPrincipalName value="DEVELOP2" />
                    </identity> -->
                </endpoint>
            </client>
        </system.serviceModel>
    My server config
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <system.serviceModel>
    	<behaviors>
            <serviceBehaviors>
              <behavior>
                <serviceMetadata httpGetEnabled="false"/>
              </behavior>
            </serviceBehaviors>
          </behaviors>
    
    <!-- Added binding to disable SecurityNegotiation exception -->
        <!-- <bindings>
           <netTcpBinding>
            <binding name = "tcpUnsecured"> 
             <security mode = "Transport"/>
            </binding> 
           </netTcpBinding>
           </bindings> -->
    
          <services>
            <service name ="MagicEightBallServiceLib2.MagicEightBallService">
       <!--    bindingConfiguration = "tcpUnsecured"  -->
              <endpoint address=""
                        binding="netTcpBinding" 
                        contract="MagicEightBallServiceLib2.IEightBall"/>
              <!--Need to add this so Mex knows address of the service-->
               <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
                    
              <host>
                <baseAddresses>
                  <add baseAddress="net.tcp://develop2:8090/MagicEightBallService"/>
                  <add baseAddress="http://develop2:8080/MagicEightBallService"/>
                </baseAddresses>
              </host>
            </service>
          </services>
        </system.serviceModel>
    </configuration>

    I'm not sure what my setting should be to get the communicaton through. 

    BtW . Visual studio generated the <Identity> section. Is this necessary in this situation.

    I removed It and it didn't seem to make a difference.

    Thanks again



    • Edited by NYBruce Thursday, August 11, 2016 5:04 AM
    • Marked as answer by NYBruce Sunday, August 14, 2016 12:20 PM
    Thursday, August 11, 2016 5:00 AM

All replies

  • Hi NYBruce,

    >> I retrieved  my remote pc's full domain name from control panel.

    Are your service and client in the same domain? If so, you do not need domain name, and you could use machine name directly in the address.

    >> From my client PC I ran a ping test to the remote ROBIN-PC running the WCF Host program to verify a communication response.

    If you try to ping service machine from client machine, will it be correct? Will you get any response from service machine?
    Based on your service’s configuration, you did not set Metadata Endpoints, something like “<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>”. Did your service run correctly and how did you generate client code and app.config file? In my option, I would suggest you add Metadata Endpoints, generate client code by Add service reference with VS, and check whether you could add it correctly.

    >> <address="net.tcp://192.168.1.19:8090/TestService/Host/MagicEightBallService"/>

    Before using it in Service, I would suggest you try to ping it from client side.

    To check whether it is related with your firewall, I would suggest you turn off your firewall in Service Machine, and then test again.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, July 12, 2016 1:11 PM
  • From my client PC I ran a ping test to the remote ROBIN-PC running the WCF Host program to verify a communication response.

    That doesn't mean any thing, because you did some Ping test and you got a response. A firewall can and does allow Ping traffic with a response sent back to the machine doing the Ping.

    Pinging doesn't account for a client program running on a remote machine trying to make the initial contact with a server program running  on another machine where the firewall has been configured to allow inbound traffic on the specified inbound port the service is listening on, called a solicitation for traffic that the FW will honor and allow the traffic to take place between the client and the service.  

    Tuesday, July 12, 2016 2:31 PM
  • Edward , 

    Thanks for your response but, Im still frustrated by my issue. FYI, my network pc's are running under WORKGROUP, not a domain. I  originally built the client proxy class using the Add Service Reference tool as suggested.  At creation time, the endpoint for MEX metadata entries were part of my service.config file and the main  endpoint for the service  was set to "binding = basicHttpbinding".  Running my service in administrator mode, I was able to verify from a web page that the metadata and WSDL information was available  for the AddServiceReference utility. I then generated the client proxy class using the utility. According to the documentation in the book "C#6.0 and the .Net 4.6 Framework" the service.config file can be minimized by removing the MEX endpoint info after the proxy is generated.  Only an entry in the <baseaddresss> element is required to indicated the location of the service and port.  I tested this by removing MEX and running both the service and proxy on a localhost. It worked whether my binding was set to "basicHttpbinding" or netTcpBinding"  When I then moved to the  client app and client.config file (with the necessary net.tcp settings for the client.config)  to another pc on the network it still does not find the server.  I ran netstat on the server pc to make sure the indicated ports were in listening mode. I also ran ping tests from the pc running the server app to the pc running the client and vice versa. Responses were received at both ends. On the server app machine, i disabled my VPN, windows firewall, AVG firewall and still no communication. ARrrrgggg.


    • Edited by NYBruce Saturday, August 6, 2016 7:22 PM
    Saturday, August 6, 2016 5:33 AM
  • I up voted your suggestion  because I appreciated the support. But I really mean to reply that I have yet to solve my issue. Please review my last response to your reply. If i need to supply more info please let me know. Thanks Edward.
    • Edited by NYBruce Monday, August 8, 2016 5:56 AM
    Monday, August 8, 2016 5:55 AM
  • Hi NYBruce,

    >> At creation time, the endpoint for MEX metadata entries were part of my service.config file and the main  endpoint for the service  was set to "binding = basicHttpbinding".

    Do you mean you use basicHttpbinding while you create service? Do you use http address or nettcp address when you add service reference?

    I made a test with below steps, it works correctly at my side. I suggest you make a test with them.
    1. Create a console application and add service
    2. Modify the app.config like below:

        <system.serviceModel>
          <behaviors>
            <serviceBehaviors>
              <behavior>
                <serviceMetadata httpGetEnabled="true"/>
              </behavior>
            </serviceBehaviors>
          </behaviors>
            <services>
                <service name="WCFNETTCP.Service1">
                    <endpoint address="" binding="netTcpBinding" contract="WCFNETTCP.IService1">
                    </endpoint>
                    <!--comment out after you add service reference-->
                    <!--<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />-->
                    <host>
                        <baseAddresses>
                            <add baseAddress="net.tcp://pc name:6666/WCFNETTCP/" />
                            <add baseAddress="http://pc name:6667/WCFNETTCIP"/>
                        </baseAddresses>
                    </host>
                </service>
            </services>
        </system.serviceModel>

    3. Host service

                ServiceHost host = new ServiceHost(typeof(Service1));
                host.Open();
                Console.WriteLine("Service is open");
                Console.ReadLine();

    4. Create a new Console application, and add service reference with address “net.tcp://pc name:6666/WCFNETTCP/mex”
    5. Client app.config

       <system.serviceModel>
            <bindings>
                <netTcpBinding>
                    <binding name="NetTcpBinding_IService1" />
                </netTcpBinding>
            </bindings>
            <client>
                <endpoint address="net.tcp://pc name:6666/WCFNETTCP/" binding="netTcpBinding"
                    bindingConfiguration="NetTcpBinding_IService1" contract="ServiceReference1.IService1"
                    name="NetTcpBinding_IService1">
                    <identity>
                        <userPrincipalName value="user principal name" />
                    </identity>
                </endpoint>
            </client>
        </system.serviceModel>

    6. Run both service and client, you could comment out mex endpoint if you need.
    7. Move Client console application to another computer which is in the same network. It works two.

    If above steps did not work, I suggest you try to create a client console application in another computer, and add service reference by the nettcp address to check whether the service could be discovered.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, August 8, 2016 11:43 AM
  • Edward,

    Thanks for getting me over the first part of my hurdle. While building a client app on a localhost or remote pc , AddServiceReference now allows me to discover service information using  the net.tcp base address. I just needed to enable mex.  I thought this was only done when binding = basicHttpbinding.  Is it true that regardless of whether you use http/net.tcp that mex must be enabled for discovery?   Is it necessary to also have an http address along with the net.tcp address in the <baseaddress> setting during Discovery time? 

    My current issue is that the client and server communicate well on the localhost pc , but not when I move the client to a remote pc.  I was able to  discover the service on the remote pc  when I built the client/proxy app using AddServiceReferene. But, when I run the client from the remote I get a SecurityNegotiationException. The detail says that the server has rejected the client credentials.  I tried fiddling around with the security binding in both config files and I'm not quite coming up with the right combination to allow communication.

    My clientr config

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
           <system.serviceModel>
            <bindings>
                <netTcpBinding>
                    <binding name="NetTcpBinding_IEightBall" />
                    <!--<binding name = "tcpUnsecured ">
                       <security mode = "Transport"/>  //also tried "None"
                      <transport clientCredentialType="Windows" />
                    </binding>-->
                </netTcpBinding>
            </bindings>
            <client>
                <endpoint address="net.tcp://develop2:8090/MagicEightBallService"
                    binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IEightBall"
                    contract="ServiceReference1.IEightBall" name="NetTcpBinding_IEightBall">
                    <!-- <identity>
                        <userPrincipalName value="DEVELOP2" />
                    </identity> -->
                </endpoint>
            </client>
        </system.serviceModel>
    My server config
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <system.serviceModel>
    	<behaviors>
            <serviceBehaviors>
              <behavior>
                <serviceMetadata httpGetEnabled="false"/>
              </behavior>
            </serviceBehaviors>
          </behaviors>
    
    <!-- Added binding to disable SecurityNegotiation exception -->
        <!-- <bindings>
           <netTcpBinding>
            <binding name = "tcpUnsecured"> 
             <security mode = "Transport"/>
            </binding> 
           </netTcpBinding>
           </bindings> -->
    
          <services>
            <service name ="MagicEightBallServiceLib2.MagicEightBallService">
       <!--    bindingConfiguration = "tcpUnsecured"  -->
              <endpoint address=""
                        binding="netTcpBinding" 
                        contract="MagicEightBallServiceLib2.IEightBall"/>
              <!--Need to add this so Mex knows address of the service-->
               <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
                    
              <host>
                <baseAddresses>
                  <add baseAddress="net.tcp://develop2:8090/MagicEightBallService"/>
                  <add baseAddress="http://develop2:8080/MagicEightBallService"/>
                </baseAddresses>
              </host>
            </service>
          </services>
        </system.serviceModel>
    </configuration>

    I'm not sure what my setting should be to get the communicaton through. 

    BtW . Visual studio generated the <Identity> section. Is this necessary in this situation.

    I removed It and it didn't seem to make a difference.

    Thanks again



    • Edited by NYBruce Thursday, August 11, 2016 5:04 AM
    • Marked as answer by NYBruce Sunday, August 14, 2016 12:20 PM
    Thursday, August 11, 2016 5:00 AM
  • Hi NYBruce,

    >> Is it true that regardless of whether you use http/net.tcp that mex must be enabled for discovery?   Is it necessary to also have an http address along with the net.tcp address in the <baseaddress> setting during Discovery time?

    Yes, mex much be enabled for discovery. I think it is necessary to have an http address. If not, you will get an error. For more information about metadata, you could refer How to: Publish Metadata for a Service Using a Configuration File.

    >> The detail says that the server has rejected the client credentials.

    Did you get this error before or after you comment out security binding in your config? In your original post, there is no configuration about security binding. It seems your current issue is related with client credentials which is different from your original issue. If so, I would suggest you post a new thread for this new issue, and mark the helpful reply as answer to close this thread.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, August 11, 2016 12:10 PM