WCF无法找到与端点的方案http匹配的基址

时间:2017-06-21 09:36:39

标签: c# wcf

当我尝试在控制台应用程序中托管WCF时,我遇到了问题。

发生异常:

  

异常:找不到与scheme http匹配的基址   绑定WSHttpBinding的端点。注册基地址   方案是[]。

这是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Text;
using System.Threading.Tasks;
using WebServiceProject.Authentication;
using WebServiceProject.Automobili;

namespace ServerHostProject
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine("--------WCF SERVICE------------");
            Console.WriteLine("Starting WCF Services please wait...");
            Console.WriteLine("-------------------------------------------");

            // Host all services

            try
            {
                // base address
                Uri baseAddress = new Uri("http://localhost:50471/services/");

                // initialize services
                ServiceHost authenticationServiceHost = new ServiceHost(typeof(AuthenticationService));
                ServiceHost automobilServiceHost = new ServiceHost(typeof(AutoService));


                // end points
                authenticationServiceHost.AddServiceEndpoint(typeof(IAuthenticationService), new WSHttpBinding(), "");
                automobilServiceHost.AddServiceEndpoint(typeof(IAutoService), new WSHttpBinding(), "");

                // metadata exchange
                ServiceMetadataBehavior serviceBehavior = new ServiceMetadataBehavior();
                serviceBehavior.HttpGetEnabled = true;

                authenticationServiceHost.Description.Behaviors.Add(serviceBehavior);
                automobilServiceHost.Description.Behaviors.Add(serviceBehavior);

                // Open 
                authenticationServiceHost.Open();
                automobilServiceHost.Open();
                Console.WriteLine("Service is started now at : {0}", baseAddress);
                Console.ReadKey();

                authenticationServiceHost.Close();
                automobilServiceHost.Close();

            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception:" + ex.Message);
            }

            Console.ReadKey();
        }
    }
}

0 个答案:

没有答案