wcf - Windows 服务总线 1.0、Appfabric、Netmessaging 绑定(bind)失败

标签 wcf appfabric servicebus

当我尝试在使用 netmessagingbinding 从 Windows Service Bus 1.0 队列接收消息的 Windows Server AppFabric 中托管 WCF 服务时,我似乎一遍又一遍地遇到同样的问题。 AppFabric 中止服务,所以如果我在 service?wsdl 上按 F5,有时会失败,有时会生成一个不错的 WSDL。我的错误在哪里?几乎不可能找到使用 AppFabric、netmessagingbinding 和 Windows 服务总线(不是 Azure)的示例,所以我没能找到我的错误...

[ServiceContract]
public interface ISBMessageService
{
    [OperationContract(IsOneWay = true, Action = "DoSomething")]
    [ReceiveContextEnabled(ManualControl = true)]
    void DoSomething(string something);
}

[ServiceBehavior]
public class SBMessageService : ISBMessageService
{
    [OperationBehavior]
    public void DoSomething(string something)
    {
        Trace.WriteLine(String.Format("You sent {0}", something));

        // Get the BrokeredMessageProperty from the current OperationContext
        var incomingProperties = OperationContext.Current.IncomingMessageProperties;
        var property = incomingProperties[BrokeredMessageProperty.Name] as BrokeredMessageProperty;

        ReceiveContext receiveContext;

        if (ReceiveContext.TryGet(incomingProperties, out receiveContext))
        {
            receiveContext.Complete(TimeSpan.FromSeconds(10.0d));
        }
        else
        {
            throw new InvalidOperationException("...");
        }             
    }
}

<?xml version="1.0"?>
<configuration>
  <appSettings>
  <!-- Service Bus specific app setings for messaging connections -->
  <add key="Microsoft.ServiceBus.ConnectionString"       
      value="Endpoint=sb://LRNcomp/LRNnamespace"/>
  </appSettings>
 <system.web>
     <compilation debug="true" targetFramework="4.0"/>
     <httpRuntime/>
 </system.web>
 <system.serviceModel>
  <!-- These <extensions> will not be needed once our sdk is installed-->
    <extensions>
      <bindingElementExtensions>
        <add name="netMessagingTransport"      type="Microsoft.ServiceBus.Messaging.Configuration.NetMessagingTransportExtensionElement, Microsoft.ServiceBus, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  </bindingElementExtensions>
  <bindingExtensions>
    <add name="netMessagingBinding" type="Microsoft.ServiceBus.Messaging.Configuration.NetMessagingBindingCollectionElement, Microsoft.ServiceBus, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  </bindingExtensions>
  <behaviorExtensions>
    <add name="transportClientEndpointBehavior" type="Microsoft.ServiceBus.Configuration.TransportClientEndpointBehaviorElement, Microsoft.ServiceBus, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  </behaviorExtensions>
</extensions>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="True" httpHelpPageEnabled="True"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="securityBehavior">
      <transportClientEndpointBehavior>
        <tokenProvider>
          <sharedSecret issuerName="owner" issuerSecret="somthing"/>
        </tokenProvider>
      </transportClientEndpointBehavior>
    </behavior>
  </endpointBehaviors>
</behaviors>
<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>
<services>
  <service name="SBExamples.SBMessageService">
    <endpoint name="Service1" address="sb://LRNcomp:9354/LRNnamespace/test/myqueue2" binding="netMessagingBinding" bindingConfiguration="messagingBinding" contract="SBExamples.ISBMessageService" behaviorConfiguration="securityBehavior"/>
  </service>
</services>
</system.serviceModel>
<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
  <!--
    To browse web app root directory during debugging, set the value below to true.
    Set to false before deployment to avoid disclosing web app folder information.
  -->
  <directoryBrowse enabled="true"/>
</system.webServer>
</configuration>

最佳答案

WCF 契约(Contract)中的一个错误产生了许多奇怪的异常,比如我的传输 channel 被中止了。发送方和接收方之间适本地共享契约(Contract)就可以达到目的。

关于wcf - Windows 服务总线 1.0、Appfabric、Netmessaging 绑定(bind)失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13788855/

相关文章:

c# - Silverlight 4 是否需要 SilverlightFaultBehavior 类?

caching - DataCache 获取所有命名区域

appfabric - 自动启动 AppFabric 缓存集群

azure - 一个客户端多次接收消息且一个客户端接收后消息被删除

c# - 无法让自己的主机在 NServiceBus 上工作

c# - 目标程序集不包含任何服务类型。您可能需要调整此程序集的代码访问安全策略

wcf - 使用 WCF WebApi 实现工作单元

c# - 缓存辅助类是单例模式的候选者吗?

.net - Azure 服务总线主题中的基础 IOException

wcf - WCF 端点的安全性