服务可以有多个端点吗?

Est*_*aya 7 .net wcf web-services

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

Dyl*_*lan 9

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

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

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

<endpoint address="https://yourdomain.com/WCF/YourService.svc"
      binding="basicHttpBinding"
      bindingConfiguration="BasicHttpBinding_IYourService"
      contract="MessagingService.IYourService"  
      name="BasicHttpBinding_IYourService" />
Run Code Online (Sandbox Code Playgroud)

你打电话给:

YourServiceClient client = new YourServiceClient();
Run Code Online (Sandbox Code Playgroud)

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

<endpoint address="https://yourotherdomain.com/WCF/YourService.svc"
      binding="basicHttpBinding"
      bindingConfiguration="BasicHttpBinding_IYourService"
      contract="MessagingService.IYourService"  
      name="BasicHttpBinding_IYourService_ENDPOINT2" />
Run Code Online (Sandbox Code Playgroud)

你可以打电话给:

YourServiceClient client = new YourServiceClient("BasicHttpBinding_IYourService_ENDPOINT2");
Run Code Online (Sandbox Code Playgroud)

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


Mar*_*ade 6

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

另请参阅MSDN文章多个端点.