.net 一个服务可以有多个端点吗?

.net 一个服务可以有多个端点吗?,.net,wcf,web-services,.net,Wcf,Web Services,我们有一个服务,它具有一些仅通过net.tcp支持的设置。添加另一个端点的最佳方式是什么?是否需要创建一个完整的新主机?一个服务在一个主机内可能有多个端点,但每个端点必须具有地址、绑定和契约的唯一组合。对于IIS托管的服务(即.SVC文件),只需将端点的地址设置为相对的URI,并确保Visual Studio或wsdl.exe生成的客户端在其构造函数中指定端点的名称 另请参阅MSDN文章。如果当前使用IIS作为主机,则需要创建一个完整的新主机-IIS仅支持HTTP而不支持TCP绑定。如果您使用W

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

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


另请参阅MSDN文章。

如果当前使用IIS作为主机,则需要创建一个完整的新主机-IIS仅支持HTTP而不支持TCP绑定。如果您使用WAS或windows服务,则只需创建一个新的net.tcp端点即可。

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

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

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

<endpoint address="https://yourdomain.com/WCF/YourService.svc"
      binding="basicHttpBinding"
      bindingConfiguration="BasicHttpBinding_IYourService"
      contract="MessagingService.IYourService"  
      name="BasicHttpBinding_IYourService" />
可以使用新名称添加新端点:

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

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

我们可以为同一个服务使用多个端点。我们还可以通过以下方式配置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>   

我认为II7确实支持非HTTP绑定(即TCP)。
YourServiceClient client = new YourServiceClient("BasicHttpBinding_IYourService_ENDPOINT2");
 <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>