none
WCF Discovery and 0.0.0.0:x address RRS feed

  • Question

  • Hi,

    I want to my WCF Service listing on all IPs. 
    I use 0.0.0.0 address in WCF Service.

    Prolem is when I use WCF Discovery, client receives a 0.0.0.0 address.

    Monday, August 12, 2013 6:34 PM

Answers

  • Hi,

    Please try to refer to the following code which use the Net.Tcp binding as an example:

    public static void StartHosts()
    {
        try
        {
            // Formulate the uri for this host
            string uri = string.Format(
                "net.tcp://0:{1}/ServerTasks",
                ServerSettings.Instance.TCPListeningPort
            );
     
            // Create a new host
            ServiceHost host = 
                new ServiceHost(typeof(ServerTasks), new Uri(uri));
     
            // Add the endpoint binding
            host.AddServiceEndpoint(
                typeof(ServerTasks),
                new NetTcpBinding(SecurityMode.Transport)
                {
                    TransferMode = TransferMode.Streamed
                },
                uri
            );
     
            // Add the meta data publishing
            var smb = 
                host.Description.Behaviors.Find<ServiceMetadataBehavior>();
            if (smb == null)
                smb = new ServiceMetadataBehavior();
     
            smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
            host.Description.Behaviors.Add(smb);
     
            host.AddServiceEndpoint(
                ServiceMetadataBehavior.MexContractName,
                MetadataExchangeBindings.CreateMexTcpBinding(),
                "net.tcp://localhost/ServerTasks/mex"
            );
     
            // Run the host
            host.Open();
        }
        catch (Exception exc)
        {
            DebugLogger.WriteException(exc);
        }
    }

    For more information, please try to refer to this article:

    #WCF: Net.Tcp Binding on all IP Addresses:
    http://mel-green.com/2009/04/wcf-nettcp-binding-on-all-ip-addresses/ .

    Best Regards.


    Amy Peng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Wednesday, August 14, 2013 2:10 AM
    Moderator

All replies

  • Hi,

    Please try to refer to the following code which use the Net.Tcp binding as an example:

    public static void StartHosts()
    {
        try
        {
            // Formulate the uri for this host
            string uri = string.Format(
                "net.tcp://0:{1}/ServerTasks",
                ServerSettings.Instance.TCPListeningPort
            );
     
            // Create a new host
            ServiceHost host = 
                new ServiceHost(typeof(ServerTasks), new Uri(uri));
     
            // Add the endpoint binding
            host.AddServiceEndpoint(
                typeof(ServerTasks),
                new NetTcpBinding(SecurityMode.Transport)
                {
                    TransferMode = TransferMode.Streamed
                },
                uri
            );
     
            // Add the meta data publishing
            var smb = 
                host.Description.Behaviors.Find<ServiceMetadataBehavior>();
            if (smb == null)
                smb = new ServiceMetadataBehavior();
     
            smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
            host.Description.Behaviors.Add(smb);
     
            host.AddServiceEndpoint(
                ServiceMetadataBehavior.MexContractName,
                MetadataExchangeBindings.CreateMexTcpBinding(),
                "net.tcp://localhost/ServerTasks/mex"
            );
     
            // Run the host
            host.Open();
        }
        catch (Exception exc)
        {
            DebugLogger.WriteException(exc);
        }
    }

    For more information, please try to refer to this article:

    #WCF: Net.Tcp Binding on all IP Addresses:
    http://mel-green.com/2009/04/wcf-nettcp-binding-on-all-ip-addresses/ .

    Best Regards.


    Amy Peng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Wednesday, August 14, 2013 2:10 AM
    Moderator
  • Hi,

    Please read first comment (user: FoTeL) on http://mel-green.com/2009/04/wcf-nettcp-binding-on-all-ip-addresses/ 

    I have this same problem.

    When the client uses WCF Discovery receives 0.0.0.0 address from WCF.


    • Edited by undertaker_ Wednesday, August 14, 2013 4:09 AM
    Wednesday, August 14, 2013 4:08 AM
  • Hi,

    I know that that you have met the same question as the author, then the author has provided the correct code in the below. Please try to check it.

    Best Regards,
    Amy Peng


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, August 19, 2013 3:22 AM
    Moderator