我有一个 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 中使用完整地址的建议来自这里: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>