将默认端点添加到自动生成的服务中

发布于 2024-11-06 02:59:51 字数 342 浏览 0 评论 0原文

我正在使用 .NET 4 和 WCF 的新功能,它们为我动态生成默认服务条目。这非常方便,因为它使我无需在配置文件中添加大约 30 个相同的(除了合同之外)服务条目。

现在我想使用发现。对于公告部分(上线和离线时发送 HelloBye)没有问题,因为我可以简单地将发现行为添加到默认行为(没有名称) )。效果很好。

但是,对于发现部分(回复发现请求),我需要向所有服务添加 DiscoveryEndpoint。这是我不知道该怎么做的部分。我在 MSDN 上找不到任何信息,我不确定它是否真的可以完成。

任何指针将不胜感激。

干杯。

I'm using the new features of .NET 4 and WCF that generate a default service entry dynamically for me. That's quite handy as it saves me from adding about 30 identical (apart from the contract) service entries in the config file.

Now I'd like to use discovery. No problem for the announce part (sending Hello and Bye when going on- and off-line) as I can simply add the discovery behaviour to the default behaviour (with no name). That works just fine.

However for the discovery part (replying to discovery requests) I would need to add a DiscoveryEndpoint to all services. That's the part that I don't know how to do. I couldn't find any information on MSDN and I'm not sure it can actually be done.

Any pointer would be appreciated.

Cheers.

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

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

发布评论

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

评论(2

半衾梦 2024-11-13 02:59:51

执行此操作的最简单方法 (AFAIK) 是创建自定义 ServiceHost/ServiceHostFactory 对,并在构造函数/OnOpening() 方法中将 DiscoveryEndpoint 添加到 ServiceHost。

如果您在 IIS 中托管服务,则需要更新 .svc 文件并将 Factory 属性指向新的 ServiceHostFactory,或者如果您使用了 WCF 4.0 中的新服务激活功能,则需要更新配置文件:

<configuration><system.serviceModel><serviceHostingEnvironment><serviceActivations>... </...

The easiest way to do this (AFAIK) is to create a custom ServiceHost/ServiceHostFactory pair and add the DiscoveryEndpoint to the ServiceHost in the constructor / OnOpening() method.

If you host your services in IIS, you either need to update your .svc files and point the Factory attribute to your new ServiceHostFactory, or if you've used the new Service Activation feature in WCF 4.0, you need to update the configuration file:

<configuration><system.serviceModel><serviceHostingEnvironment><serviceActivations>... </...
一生独一 2024-11-13 02:59:51

正确的方法是创建一个包含 serviceDiscovery 元素的默认服务行为:

<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
                <serviceDiscovery>
                    <announcementEndpoints>
                        <endpoint
                   name="MyAnnouncementEndpoint"
                   kind="announcementEndpoint"
                   address="net.tcp://localhost/My.ServiceLocator/DiscoveryProxy.svc"
                   bindingConfiguration ="NetTcpBindingConfiguration"
                   binding="netTcpBinding"/>

                    </announcementEndpoints>
                </serviceDiscovery>
            </behavior>
  </serviceBehaviors>
</behaviors>

这样您的所有服务都将使用此默认行为,即使是您未明确声明的服务。

The way to go is creating a default Service Behavior that includes the serviceDiscovery element:

<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
                <serviceDiscovery>
                    <announcementEndpoints>
                        <endpoint
                   name="MyAnnouncementEndpoint"
                   kind="announcementEndpoint"
                   address="net.tcp://localhost/My.ServiceLocator/DiscoveryProxy.svc"
                   bindingConfiguration ="NetTcpBindingConfiguration"
                   binding="netTcpBinding"/>

                    </announcementEndpoints>
                </serviceDiscovery>
            </behavior>
  </serviceBehaviors>
</behaviors>

This way all your services will use this default behavior even the ones you don't explicitly declare.

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