【问题标题】:Can a service have multiple endpoints?一个服务可以有多个端点吗?
【发布时间】:2008-09-05 16:50:44
【问题描述】:

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

【问题讨论】:

    标签: .net wcf web-services


    【解决方案1】:

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

    要在客户端上执行此操作,您只需使用具有不同名称的新端点编辑 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”值。

    【讨论】:

      【解决方案2】:

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

      另请参阅 MSDN 文章 Multiple Endpoints

      【讨论】:

        【解决方案3】:

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

        【讨论】:

        • 我认为 II7 确实支持非 HTTP 绑定(即 TCP)。
        【解决方案4】:

        我们可以为同一个服务使用多个端点。我们也可以通过以下方式配置 web config

         <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>   
        

        【讨论】:

          猜你喜欢
          • 2020-02-03
          • 1970-01-01
          • 2012-10-01
          • 2017-02-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-09-09
          • 2019-10-09
          相关资源
          最近更新 更多