Adding scopes to the announcement endpoint
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
collectio开发者_JS百科n 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.
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.
精彩评论