WCF服务在2个不同的服务合同上公开2个端点

Cor*_*Doe 7 c# wcf web-services endpoint servicecontract

我有一个WCF服务,我试图配置,以便它在不同的URL下公开2个端点,引用不同的功能.

我想要的是Service1,暴露方法A,B,C和Service2,暴露方法D,E.我希望能够浏览localhost/WebServiceName/Service1/Service.svclocalhost/WebServiceName/Service2/Service .svc.

引用localhost/WebServiceName/Service1/Service.svc的其他应用程序应该只看到包含方法A,B和C的接口.它们不应该看到有关Service2接口的任何内容.而对于Service2同样如此.

到目前为止,我已经在我的WCF服务中定义了两个接口,I_Service1I_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" />  
Run Code Online (Sandbox Code Playgroud)

在这里使用完整地址的建议来自这里: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. 
Run Code Online (Sandbox Code Playgroud)

我可以成功浏览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>
Run Code Online (Sandbox Code Playgroud)

Cor*_*Doe 3

目前我对这个问题的解决方案是在我的 web 服务中合并两个 .svc 文件来分隔两个接口。这样,我有localhost/WebServiceName/Service1.svclocalhost/WebServiceName/Service2.svc

通过端点配置

<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.svc" />
       </baseAddresses>
     </host>
   </service>
   <service behaviorConfiguration="WebServiceName.ServiceBehavior2" name="WebServiceName.Service2">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding2"
     contract="WebServiceName.I_Service2" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
     <host>
       <baseAddresses>
         <add baseAddress="http://localhost/WebServiceName/Service1.svc" />
       </baseAddresses>
     </host>
   </service>
  </services>
Run Code Online (Sandbox Code Playgroud)

该解决方案不一定是最好的解决方案(如果客户端确实想要,它可以发现该服务公开了 2 个不同的接口,但我可以使用不同的凭据/令牌来保护它们)。但目前我会接受它。