WCF service host cannot find any service metadata

后端 未结 10 579
余生分开走
余生分开走 2020-12-16 13:01

I\'m just learning wcf and currently got this far.

CS File:

using System;
using System.Collections.Generic;
using System.Linq;
using         


        
10条回答
  •  孤城傲影
    2020-12-16 13:19

    // get the  /  config section
    ServicesSection services = ConfigurationManager.GetSection("system.serviceModel/services") as ServicesSection;
    
    ServiceHost host = new ServiceHost(typeof(SelfHostedService.Service));
    
    // enumerate over each  node
    foreach (ServiceElement aService in services.Services)
    {
        Console.WriteLine();
        Console.WriteLine("Name: {0} / Behavior: {1}", aService.Name, aService.BehaviorConfiguration);
    
        // enumerate over all endpoints for that service
        foreach (ServiceEndpointElement see in aService.Endpoints)
        {
            Console.WriteLine("\tEndpoint: Address = {0} / Binding = {1} / Contract = {2}", see.Address, see.Binding, see.Contract);
            //host.AddServiceEndpoint(
        }
    }
    
    try
    {
        Console.WriteLine("Service EndPoints are: ");
        foreach (ServiceEndpoint endpoint in host.Description.Endpoints)
        {
            Console.WriteLine("{0} ({1})", endpoint.Address.ToString(), endpoint.Binding.Name);
        }
        host.Open();
    
        Console.WriteLine(string.Concat("Service is host at ", DateTime.Now.ToString()));
        Console.WriteLine("\n Self Host is running... Press  key to stop");
    }
    catch(Exception ex)
    {
        Console.WriteLine(ex.Message.ToString());
    }
    

    If still not work so delete current config file and reCreate it with its default name App.config, this is works.

提交回复
热议问题