【问题标题】:WCF and Windows Server Service Bus EndpointsWCF 和 Windows Server 服务总线终结点
【发布时间】:2013-04-23 07:38:30
【问题描述】:

我需要开发一个 Windows Server Service Bus 主题订阅者(是的,Windows Server 而不是 Azure),并且为了从阅读中抽象出来,启动工作线程,...,循环并利用 AppFabric 管理能力,我有以下想法:

  • 开发 WCF 服务
  • 定义 Windows Server 服务总线端点

问题是:

  1. 发布者必须使用服务合同向主题发送消息?
  2. 配置文件应该是什么样的?

提前致谢。

【问题讨论】:

    标签: wcf appfabric servicebus


    【解决方案1】:

    如何连接 WCF 和服务总线的基本机制在 Azure 和服务器版本之间是相同的。 You can use this post as a good starting point:

    两者之间的主要区别在于端点地址,以及如何处理身份验证(因为服务器中没有 ACS)。 This post has some useful information on it.

    现在,具体回答您的问题:

    • 从技术上讲,发布者可以直接推送到服务总线队列,但最好使用合同。这里的问题不是如何推送,而是如何以服务可以理解的方式构建消息。拥有 WCF 合同可以让您将序列化/反序列化抽象出来。

    • 对于配置,典型情况是有一个使用netMessagingBinding 的 WCF 服务。我提到的第一篇文章有​​关于配置的信息。只需确保更新身份验证和端点地址片段以匹配服务总线服务器。

    【讨论】:

    • 谢谢拉米罗。使用 netMessageBinding 我可以向主题发布消息,并且显然可以从订阅中接收消息。但是,即使消息是从订阅中消费的,它们似乎也不会由服务本身处理。我构建了一个简单的 IDispatchMessageInspector 拦截器实现,但如果我使用的是 SB 端点,它不会被调用。如果我使用的是 Http 端点,就会调用它。
    • 您在哪里托管您的网络服务?如果您使用的是 IIS,则需要首先激活服务(在 IIS 的模型中,WCF 在请求到来之前不会变为活动状态)。关于如何设置 IIS 以使用 SB 的文档在这里:msdn.microsoft.com/en-us/library/windowsazure/hh966775.aspx
    • 看来问题是由于端点配置无效。 address 属性必须包含主题 URI,而 listenURI 指向订阅 URI。感谢您的帮助!
    • 大家好——我在 Service Bus 文档团队工作,我们意识到这篇文章中标题为 This post has some useful information on it 的链接不再存在。我建议您改为查看此主题:Getting Started with Service Bus for Windows Server 1.1,其中包含类似(但更有用!)的信息。谢谢,请保持反馈!我们在听……
    【解决方案2】:

    为了帮助未来的相关问题,这里是必需的配置

    发布者和订阅者配置都需要扩展

    <extensions>
      <behaviorExtensions>
        <add name="transportClientEndpointBehavior" type="Microsoft.ServiceBus.Configuration.TransportClientEndpointBehaviorElement, Microsoft.ServiceBus, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </behaviorExtensions>
    
      <bindingExtensions>
        <add name="netMessagingBinding" type="Microsoft.ServiceBus.Messaging.Configuration.NetMessagingBindingCollectionElement, Microsoft.ServiceBus, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </bindingExtensions>
    </extensions>
    

    注意:发布者和订阅者都需要 Microsoft.ServiceBus 程序集。该软件包在Nuget 中提供。

    订阅者端配置

    <bindings>
      <netMessagingBinding>
        <binding name="messagingBinding" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:03:00" sendTimeout="00:03:00" sessionIdleTimeout="00:01:00" prefetchCount="-1">
          <transportSettings batchFlushInterval="00:00:01" />
        </binding>
      </netMessagingBinding>
    </bindings>
    
    <behaviors>
      <endpointBehaviors>
        <behavior name="securityBehavior">
          <messageInterceptorBehavior/>
          <transportClientEndpointBehavior>
            <tokenProvider>
              <windowsAuthentication>
                <stsUris>
                  <stsUri value="https://[SERVER]:9355/[NAMESPACE]" />
                </stsUris>
              </windowsAuthentication>
            </tokenProvider>
          </transportClientEndpointBehavior>
    </behavior>
    
    <endpoint listenUri="sb://[SERVER]/[NAMESPACE]/[TOPIC]/Subscriptions/[SUBSCRIPTIONNAME]"
                  address="sb://[SERVER]/[NAMESPACE]/[TOPIC]"
                  behaviorConfiguration="securityBehavior" binding="netMessagingBinding"
                  bindingConfiguration="messagingBinding" name="InsuranceService"
                  contract="[WCF_CONTRACT_NAME]" />
    

    发布者配置

    <bindings>
      <netMessagingBinding>
        <binding name="InsuranceService" closeTimeout="00:03:00" openTimeout="00:03:00"
          receiveTimeout="00:03:00" sendTimeout="00:03:00" prefetchCount="-1"
          sessionIdleTimeout="00:01:00">
          <transportSettings batchFlushInterval="00:00:01" />
        </binding>
      </netMessagingBinding>
    </bindings>
    
    <behaviors>
      <endpointBehaviors>
        <behavior name="securityBehavior">
          <messageInterceptorBehavior/>
          <transportClientEndpointBehavior>
            <tokenProvider>
              <windowsAuthentication>
                <stsUris>
                  <stsUri value="https://[SERVER]:9355/[NAMESPACE]" />
                </stsUris>
              </windowsAuthentication>
            </tokenProvider>
          </transportClientEndpointBehavior>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    
    <client>
      <endpoint address="sb://[SERVER]/[NAMESPACE]/[TOPIC]"
        behaviorConfiguration="securityBehavior" binding="netMessagingBinding"
        bindingConfiguration="InsuranceService" contract="PushVoucherService.ISubscriber"
        name="InsuranceService" />
    </client>
    

    【讨论】:

      猜你喜欢
      • 2015-03-22
      • 2015-01-09
      • 1970-01-01
      • 2012-01-16
      • 1970-01-01
      • 2017-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多