Add service reference when using netTcp binding

后端 未结 3 975
忘了有多久
忘了有多久 2020-12-28 09:37

I have a WCF service that I tested by copying its interfaces to a sample client project.
Now I want to work properly by adding a service reference.

3条回答
  •  遥遥无期
    2020-12-28 10:32

    You need to do:

    1. maxHttpBinding -> mexTcpBinding - you cannot use mexHttpBinding on net.tcp endpoint (and it's mex not max)
    2. the contract for mex endpoint must be IMetadataExchange - as you want to have service metadata available through this endpoint
    3. httpGetEnabled="false" as there will be no http endpoint to get metadata from
    4. When I was testing the solution in a simple console host I needed to change name in tag to Externals.ExecutionService (but this depends on how you instantiate the service)

    Then your service reference will be available at: net.tcp://localhost:3040/ExecutionService/mex as base address is net.tcp://localhost:3040/ExecutionService and the relative address for the mex endpoint is set to mex

    Final app.config is below:

    
    
    
    
      
        
        
        
          
            
          
        
      
    
    
      
        
          
          
        
      
    
    
    
    

    For a quick test if the configuration is correct I used console host app as a service host. Program.cs:

    using System;
    using System.ServiceModel;
    
    namespace Externals
    {
        class Program
        {
            static void Main(string[] args)
            {
    
                var sh=new ServiceHost(typeof(ExecutionService));
                sh.Open();
                Console.WriteLine("Service running press any key to terminate...");
                Console.ReadKey();
                sh.Close();
            }
        }
    }
    

    Run the console app and try to add service reference to your project through net.tcp://localhost:3040/ExecutionService/mex.

提交回复
热议问题