将范围添加到公告端点

发布于 2024-11-10 17:29:26 字数 1475 浏览 3 评论 0原文

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

将范围添加到发现端点效果很好,但我无法找出公告端点的正确配置。这是我的想法:

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

我认为这是不正确的,因为我重用了为发现端点创建的端点行为。但这是我发现描述我的范围的唯一方式。

我认为使用公告范围应该是可能的,因为:

  • 没有其他方法来过滤收到的公告
  • EndpointDiscoveryMetadata 类(我在收到公告时获得的实例)包含一个属性 范围

但根据我的配置,客户端的 Scopes 集合对于除 mex 端点之外的所有端点都是空的(其中有两个 tempuri 范围)。

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

I'm currently implementing a service that uses WCF discovery and provides Discovery Endpoint and Announcement Endpoint. I also need to use scopes in order to filter announced/discovered endpoints on my client.

Adding scopes to the Discovery Endpoint works great, but I can't figure out the right configuration for Announcement Endpoint. Here's what I came up with:

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

I suppose it's not correct because I reuse the endpoint behavior that I created for my Discovery Endpoint. But that's the only way I found to describe my scopes.

I think that using scopes for announcements should be possible because:

  • There is no other way to filter received announcements
  • The EndpointDiscoveryMetadata class (the instance of which I get when announcements get received) contains a property Scopes.

But with my configuration the Scopes collection on client side is empty for all endpoints except the mex one (it has two tempuri scopes in it).

So, any ideas how to correctly declare scopes for the announcement endpoints?
Any help will be appreciated, many thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不知所踪 2024-11-17 17:29:26

实际上,我自己就弄清楚了(嗯,在 来自 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>

这有效,我在客户端得到了我的范围。我希望它能帮助某人。

Actually, just figured it out myself (well, with help of Configuration sample from MSDN that I didn't find earlier).

The key is to apply DiscoveryBehavior to all discoverable service endpoints rather than to an announcement endpoint.

So,

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

This works and I get my scopes at client side. I hope it helps someone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文