【问题标题】:Adding scopes to the announcement endpoint向公告端点添加范围
【发布时间】:2011-05-31 04:43:35
【问题描述】:

我目前正在实施一项使用WCF discovery 并提供发现端点和公告端点的服务。我还需要使用范围来过滤客户端上宣布/发现的端点。

向 Discovery Endpoint 添加范围效果很好,但我无法确定 Announcement Endpoint 的正确配置。这是我想出的:

<serviceBehaviors>
    <behavior name="MyServiceBehavior">
        <serviceMetadata httpGetEnabled="True"/>
        <serviceDiscovery>
            <announcementEndpoints>
                <endpoint kind="udpAnnouncementEndpoint"      
                          behaviorConfiguration="DiscoveryBehavior" />                          
            </announcementEndpoints>
        </serviceDiscovery>
    </behavior>
</serviceBehaviors>
<endpointBehaviors>
    <behavior name="DiscoveryBehavior">
        <endpointDiscovery>
            <scopes>
                <add scope="http://My/Scope"/>
            </scopes>
        </endpointDiscovery>
    </behavior>
</endpointBehaviors>

我认为这不正确,因为我重用了我为 Discovery Endpoint 创建的端点行为。但这是我发现描述我的作用域的唯一方法。

我认为应该可以使用范围进行公告,因为:

  • 没有其他方法可以过滤收到的通知
  • EndpointDiscoveryMetadata 类(我在收到通知时获得的实例)包含一个属性 Scopes

但在我的配置下,客户端的 Scopes 集合对于所有端点都是空的,除了 mex 端点(它有两个 tempuri 范围)。

那么,有什么想法可以正确声明公告端点的范围吗? 任何帮助将不胜感激,非常感谢。

【问题讨论】:

    标签: wcf service-discovery scopes


    【解决方案1】:

    实际上,我只是自己想出来的(好吧,在我之前没有找到的 Configuration sample from MSDN 的帮助下)。

    关键是将 DiscoveryBehavior 应用于所有可发现的服务端点而不是公告端点

    所以,

    <services>
        <service name="MyService" behaviorConfiguration="MyServiceBehavior">
            <endpoint address="MyService/" binding="wsHttpBinding"
                      contract="IMyService"
                      behaviorConfiguration="DiscoveryBehavior" />
            <endpoint address="mex" binding="mexHttpBinding" 
                      contract="IMetadataExchange"/>
            <endpoint kind="udpDiscoveryEndpoint" />
        </service>
    </services>
    
    <behaviors>
        <serviceBehaviors>
        <behavior name="MyServiceBehavior">
            <serviceMetadata httpGetEnabled="True"/>
            <serviceDiscovery>
                <announcementEndpoints>
                    <endpoint kind="udpAnnouncementEndpoint" />                          
                </announcementEndpoints>
            </serviceDiscovery>
        </behavior>
        </serviceBehaviors>
    
        <endpointBehaviors>
            <behavior name="DiscoveryBehavior">
                <endpointDiscovery>
                    <scopes>
                        <add scope="http://My/Scope"/>
                    </scopes>
                </endpointDiscovery>
            </behavior>
        </endpointBehaviors>
    </behaviors>
    

    这行得通,我在客户端得到了我的范围。我希望它可以帮助某人。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 2018-11-28
      • 2016-10-24
      相关资源
      最近更新 更多