【发布时间】:2012-11-24 09:22:19
【问题描述】:
我有一个 WCF 服务,我正在尝试对其进行配置,以便它公开 2 个端点,在不同的 URL 下引用不同的功能。
我想要的是 Service1,公开方法 A、B、C 和 Service2,公开方法 D、E。 我希望能够同时浏览 localhost/WebServiceName/Service1/Service.svc 和 localhost/WebServiceName/Service2/Service.svc。
引用 localhost/WebServiceName/Service1/Service.svc 的其他应用程序应该只看到包含方法 A、B 和 C 的接口。它们应该看不到任何关于 Service2 的内容界面。对于 Service2 也是如此。
到目前为止,我已经在我的 WCF 服务中定义了两个接口,I_Service1 和 I_Service2。
我在 web.config 中添加了两个端点,如下所示:
<endpoint address="http://localhost/WebServiceName/Service1/" binding="wsHttpBinding" contract="WebServiceName.I_Service1" bindingConfiguration="Binding1" />
<endpoint address="http://localhost/WebServiceName/Service2/" binding="wsHttpBinding" contract="WebServiceName.I_Service2" bindingConfiguration="Binding2" />
在enpoint中使用完整地址的建议来自这里:Multiple endpoints under IIS
但是,我仍然无法浏览 localhost/WebServiceName/Service1/Service.svc。我收到:
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
我可以成功浏览localhost/WebServiceName/Service.svc,并且wsdl包括方法A、B、C、D、E。但这在我想要的行为中应该是错误的。
我有什么遗漏的吗?
更新:在这篇文章http://allen-conway-dotnet.blogspot.ro/2011/09/exposing-multiple-binding-types-for.html 之后,我为这些端点创建了两个不同的合同服务。但目前我浏览它时只看到 Service1。 Service2 显然不存在(出现与 HTTP 404 错误相关的问题)。
配置如下:
<services>
<service behaviorConfiguration="WebServiceName.ServiceBehavior1" name="WebServiceName.Service1">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1"
contract="WebServiceName.I_Service1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/WebServiceName/Service1/Service.svc" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="WebServiceName.ServiceBehavior2" name="WebServiceName.Service2">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1"
contract="WebServiceName.I_Service2" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/WebServiceName/Service2/Service.svc" />
</baseAddresses>
</host>
</service>
</services>
【问题讨论】:
标签: c# wcf web-services endpoint servicecontract