服务可以有多个端点吗?

时间:2008-09-05 16:50:45

标签: .net wcf web-services

我们的服务有一些仅通过net.tcp支持的设置。添加另一个端点的最佳方法是什么?我是否需要创建一个全新的主机?

4 个答案:

答案 0 :(得分:9)

您可以在服务器或客户端上定义多个端点。

要在客户端上执行此操作,您只需使用具有不同名称的新端点编辑app.config文件,然后定义何时创建新客户端。

例如,如果您的客户端应用中有一个端点,如:

<endpoint address="https://yourdomain.com/WCF/YourService.svc"
      binding="basicHttpBinding"
      bindingConfiguration="BasicHttpBinding_IYourService"
      contract="MessagingService.IYourService"  
      name="BasicHttpBinding_IYourService" />

你打电话:

YourServiceClient client = new YourServiceClient();

您可以使用新名称添加新端点:

<endpoint address="https://yourotherdomain.com/WCF/YourService.svc"
      binding="basicHttpBinding"
      bindingConfiguration="BasicHttpBinding_IYourService"
      contract="MessagingService.IYourService"  
      name="BasicHttpBinding_IYourService_ENDPOINT2" />

您可以致电:

YourServiceClient client = new YourServiceClient("BasicHttpBinding_IYourService_ENDPOINT2");

我刚刚更改了上面的域名,但是如果您创建了新的绑定配置部分,则可以更改“bindingConfiguration”值。

答案 1 :(得分:6)

服务可能在单个主机中有多个端点,但每个端点必须具有地址,绑定和合同的唯一组合。对于IIS托管的服务(即.SVC文件),只需将端点的地址设置为 relative URI,并确保您的Visual Studio或wsdl.exe生成的客户端指定端点的名称在其构造函数中。

另请参阅MSDN文章 Multiple Endpoints

答案 2 :(得分:0)

如果您当前使用IIS作为主机,则需要创建一个全新的主机 - IIS仅支持HTTP而不支持TCP绑定。但是,如果您使用的是WAS或Windows服务,那么只需创建一个新的net.tcp端点即可轻松实现。

答案 3 :(得分:0)

我们可以将多个端点用于同一服务。我们也可以通过以下方式配置Web配置

 <service name="MessagePatternDemo.Service1">  
 <endpoint name="ep1" address="/ep1" binding="basicHttpBinding" 
   contract="MessagePatternDemo.IService1"/>  
 <endpoint name="ep2" address="/ep2" binding="wsHttpBinding"  
   contract="MessagePatternDemo.IService1" />  
 <endpoint name="mex" contract="IMetadataExchange" address="mex"  
   binding="mexHttpBinding" />  
 </service>   
相关问题