实现多个服务契约的 WCF 类
我有一个类 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();
我收到运行时错误:
HttpGetEnabled 属性 ServiceMetadataBehavior 设置为 true 并且 HttpGetUrl 属性是 相对地址,但是没有http 基址。要么提供一个 http 基地址或将 HttpGetUrl 设置为 绝对地址。
我能做什么呢?我真的需要两个单独的端点吗?
I have a class TestService
which implements two service contracts called IService1
and IService2
. But I'm facing a difficulty in implementation.
My code looks as follows:
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();
I'm getting a run time error as:
The HttpGetEnabled property of
ServiceMetadataBehavior is set to true
and the HttpGetUrl property is a
relative address, but there is no http
base address. Either supply an http
base address or set HttpGetUrl to an
absolute address.
What can I do about it? Do I really need two separate endpoints?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过两种方式修复它
1)
2)
you can fix it in two ways
1)
2)
您所需要做的就是添加基地址。
您仍然有两个独立的端点。
All you need to do is to add an base address.
you still have two separated endpoints.