我有一个类,它实现了两个名为and的TestService
服务合同。但我在实施中面临困难。IService1
IService2
我的代码如下所示:
Uri baseAddress = new Uri("http://localhost:8000/ServiceModel/Service");
Uri baseAddress1 = new Uri("http://localhost:8080/ServiceModel/Service1");
ServiceHost selfHost = new ServiceHost(typeof(TestService));
selfHost.AddServiceEndpoint(typeof(IService1), new WSHttpBinding(), baseAddress);
selfHost.AddServiceEndpoint(typeof(IService2), new WSHttpBinding(), baseAddress1);
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
selfHost.Open();
Console.WriteLine("The service is ready.");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.WriteLine();
Console.ReadLine();
selfHost.Close();
我收到一个运行时错误:
ServiceMetadataBehavior的HttpGetEnabled属性设置为true,HttpGetUrl属性是相对地址,但是没有http基地址。提供 http 基地址或将 HttpGetUrl 设置为绝对地址。
我能做些什么呢?我真的需要两个独立的端点吗?