2012-09-05 73 views
3

我使用Azure ServiceBus API發佈到Service Bus上。 sb協議在防火牆後面不起作用。因此,我將ServiceBusEnvironment.SystemConnectivity.Mode設置爲ConnectivityMode.Http。只要我直接連接到互聯網,這就工作了。即使在配置了http代理之後,這也不適用於我的辦公室。 ServiceBus API有問題嗎?感謝您的幫助。通過http後臺代理髮布到Azure服務總線

下面是一塊的,我用的代碼....

public static void Initialize() 
    { 
     // Using Http to be friendly with outbound firewalls 
     ServiceBusEnvironment.SystemConnectivity.Mode = 
      ConnectivityMode.Http; 

     //InitializeQueue(); 
    } 


    // The name of your queue 
    public const string QueueName = "ordersqueue"; 

    public static NamespaceManager CreateNamespaceManager() 
    { 
     // Create the namespace manager which gives you access to 
     // management operations 
     var uri = ServiceBusEnvironment.CreateServiceUri(
      "sb", Namespace, String.Empty); 
     var tP = TokenProvider.CreateSharedSecretTokenProvider(
      IssuerName, IssuerKey); 
     return new NamespaceManager(uri, tP); 
    } 

    private static void InitializeQueue() 
    { 
     // Create the namespace manager which gives you access to 
     // management operations 
     var namespaceManager = CreateNamespaceManager(); 

     // Create the queue if it does not exist already 
     if (!namespaceManager.QueueExists(QueueName)) 
     { 
      namespaceManager.CreateQueue(QueueName); 
     } 

     // Get a client to the queue 
     var messagingFactory = MessagingFactory.Create(
      namespaceManager.Address, 
      namespaceManager.Settings.TokenProvider); 
     OrdersQueueClient = messagingFactory.CreateQueueClient(
      QueueName); 
    } 

下面是堆棧跟蹤我得到................... ............. .................................... ...........................

Microsoft.ServiceBus.Messaging.MessagingCommunicationException was unhandled 
    Message=Unable to connect to ServiceBus using HTTP connectivity mode 
    Source=Microsoft.ServiceBus 
    IsTransient=true 
    StackTrace: 
     at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageSender.EndSendCommand(IAsyncResult result) 
     at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageSender.OnEndSend(IAsyncResult result) 
     at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageSender.OnSend(TrackingContext trackingContext, IEnumerable`1 messages, TimeSpan timeout) 
     at Microsoft.ServiceBus.Messaging.MessageSender.Send(TrackingContext trackingContext, IEnumerable`1 messages, TimeSpan timeout) 
     at Microsoft.ServiceBus.Messaging.MessageSender.Send(BrokeredMessage message) 
     at Microsoft.ServiceBus.Messaging.QueueClient.Send(BrokeredMessage message) 
     at AzureServiceBusPublisher.QueueConnector.send(String arg) in C:\Users\prasanh\Documents\Visual Studio 2010\Projects\AzureServiceBusPublisher\AzureServiceBusPublisher\QueueConnector.cs:line 72 
     at AzureServiceBusPublisher.Program.sendMessagesToQueue() in C:\Users\prasanh\Documents\Visual Studio 2010\Projects\AzureServiceBusPublisher\AzureServiceBusPublisher\Program.cs:line 23 
     at AzureServiceBusPublisher.Program.Main(String[] args) in C:\Users\prasanh\Documents\Visual Studio 2010\Projects\AzureServiceBusPublisher\AzureServiceBusPublisher\Program.cs:line 13 
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
     at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
     at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ThreadHelper.ThreadStart() 
    InnerException: System.ServiceModel.CommunicationException 
     Message=Unable to connect to ServiceBus using HTTP connectivity mode 
     Source=Microsoft.ServiceBus 
     StackTrace: 
     Server stack trace: 
      at Microsoft.ServiceBus.WebStream..ctor(Uri factoryEndpointUri, String webSocketRole) 
      at Microsoft.ServiceBus.WebSocketConnection..ctor(Uri factoryEndpointUri, String webSocketRole, Int32 asyncReadBufferSize) 
      at Microsoft.ServiceBus.WebSocketOnewayConnectionInitiator.Connect(Uri uri, TimeSpan timeout) 
      at Microsoft.ServiceBus.WebSocketOnewayConnectionInitiator.BeginConnect(Uri uri, TimeSpan timeout, AsyncCallback callback, Object state) 
      at Microsoft.ServiceBus.Channels.BufferedConnectionInitiator.BeginConnect(Uri uri, TimeSpan timeout, AsyncCallback callback, Object state) 
      at Microsoft.ServiceBus.Channels.ConnectionPoolHelper.EstablishConnectionAsyncResult.OpenUsingNewConnection() 
      at Microsoft.ServiceBus.Channels.ConnectionPoolHelper.EstablishConnectionAsyncResult.Begin() 
      at Microsoft.ServiceBus.Channels.ConnectionPoolHelper.EstablishConnectionAsyncResult..ctor(ConnectionPoolHelper parent, TimeSpan timeout, AsyncCallback callback, Object state) 
      at Microsoft.ServiceBus.Channels.ConnectionPoolHelper.BeginEstablishConnection(TimeSpan timeout, AsyncCallback callback, Object state) 
      at Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.OpenAsyncResult..ctor(ClientFramingDuplexSessionChannel duplexChannel, TimeSpan timeout, AsyncCallback callback, Object state) 
      at Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.OnBeginOpen(TimeSpan timeout, AsyncCallback callback, Object state) 
      at Microsoft.ServiceBus.Channels.CommunicationObject.OpenAsyncResult..ctor(CommunicationObject communicationObject, TimeSpan timeout, AsyncCallback callback, Object state) 
      at Microsoft.ServiceBus.Channels.CommunicationObject.BeginOpen(TimeSpan timeout, AsyncCallback callback, Object state) 
      at Microsoft.ServiceBus.Channels.LayeredChannel`1.OnBeginOpen(TimeSpan timeout, AsyncCallback callback, Object state) 
      at Microsoft.ServiceBus.Channels.CommunicationObject.OpenAsyncResult..ctor(CommunicationObject communicationObject, TimeSpan timeout, AsyncCallback callback, Object state) 
      at Microsoft.ServiceBus.Channels.CommunicationObject.BeginOpen(TimeSpan timeout, AsyncCallback callback, Object state) 
      at Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.OnBeginOpen(TimeSpan timeout, AsyncCallback callback, Object state) 
      at System.ServiceModel.Channels.CommunicationObject.OpenAsyncResult.InvokeOpen() 
      at System.ServiceModel.Channels.CommunicationObject.OpenAsyncResult..ctor(CommunicationObject communicationObject, TimeSpan timeout, AsyncCallback callback, Object state) 
      at System.ServiceModel.Channels.CommunicationObject.BeginOpen(TimeSpan timeout, AsyncCallback callback, Object state) 
      at Microsoft.ServiceBus.Messaging.Channels.SharedChannel`1.GetInstanceAsyncResult.<GetAsyncSteps>b__3(GetInstanceAsyncResult thisPtr, TimeSpan t, AsyncCallback c, Object s) 
      at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.EnumerateSteps(CurrentThreadType state) 
      at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.Start() 
     Exception rethrown at [0]: 
      at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result) 
      at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.End(IAsyncResult asyncResult) 
      at Microsoft.ServiceBus.Messaging.Channels.SharedChannel`1.OnEndCreateInstance(IAsyncResult asyncResult) 
      at Microsoft.ServiceBus.Messaging.SingletonManager`1.EndGetInstance(IAsyncResult asyncResult) 
      at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.RequestAsyncResult.<GetAsyncSteps>b__f(RequestAsyncResult thisPtr, IAsyncResult r) 
      at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.EnumerateSteps(CurrentThreadType state) 
     Exception rethrown at [1]: 
      at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result) 
      at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.End(IAsyncResult asyncResult) 
      at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.EndRequest(IAsyncResult result) 
      at Microsoft.ServiceBus.Messaging.Sbmp.SbmpTransactionalAsyncResult`1.<GetAsyncSteps>b__44(TIteratorAsyncResult thisPtr, IAsyncResult a) 
      at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.EnumerateSteps(CurrentThreadType state) 
     Exception rethrown at [2]: 
      at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result) 
      at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.End(IAsyncResult asyncResult) 
      at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageSender.EndSendCommand(IAsyncResult result) 
     InnerException: System.ServiceModel.CommunicationException 
      Message=Unable to connect downstream 
      Source=Microsoft.ServiceBus 
      StackTrace: 
       at Microsoft.ServiceBus.WebStream.CreateDownStreamRequest(Uri endpointLocation) 
       at Microsoft.ServiceBus.WebStream.StartSession(Uri readEndpoint, Uri writeEndpoint) 
       at Microsoft.ServiceBus.WebStream..ctor(Uri factoryEndpointUri, String webSocketRole) 
      InnerException: System.Net.WebException 
       Message=The remote server returned an error: (403) Forbidden. 
       Source=System 
       StackTrace: 
         at System.Net.HttpWebRequest.GetResponse() 
         at Microsoft.ServiceBus.WebStream.CreateDownStreamRequest(Uri endpointLocation) 
       InnerException: 

回答

2

什麼是詳細的異常明白嗎?

根據我的經驗,太多的代理不支持HTTP 1.1的默認配置。服務總線正常工作需要HTTP 1.1。

除此之外,我建議你檢查這guide to troubleshoot connectivity to Service Bus

+0

您遇到的詳細異常應該有一條消息,例如「無法使用HTTP連接模式連接到ServiceBus」以及異常鏈中的更深層次「HTTP/1.0協議不支持」Chunked編碼上傳「。 – DavideB

+0

謝謝。我收到錯誤消息「無法使用HTTP連接模式連接到ServiceBus」,但深入它沒有分塊錯誤。相反,它有錯誤消息「遠程服務器返回錯誤:(403)禁止」。爲什麼我會得到這個錯誤?在通過sb協議進行連接時,我沒有得到這個錯誤,但是沒有代理連接時我沒有得到這個錯誤。 – phebbar

+0

我想你檢查了[故障排除指南]中的所有內容(http://social.technet.microsoft.com/wiki/contents/articles/troubleshooting-connectivity-issues-in-the-windows-azure-appfabric-service-bus .aspx):通過瀏覽器進行訪問,ping測試以及其他所有事情都可以從代理後臺完成?指南(代理配置)中的第4部分可能會有用。 IMO它可能是一個與代理有關的問題,即使我可能發現HTTP 403錯誤有點令人困惑。 你的代碼是好的,也是憑據,否則它會通過TCP失敗;因此網絡訪問是進一步調查的其餘領域。 – DavideB

1

我在Windows Azure的服務總線隊的SDE。請嘗試發佈指南。

另請注意,自SDK 1.7起,Service Bus Messaging僅適用於支持POST分塊的HTTP 1.1代理。我們正在爲此制定一個長期解決方案,即將發佈的SDK 1.8允許Service Bus Relay使用HTTPS而不是POST分塊來處理這些代理以及HTTP 1.0代理。

我們也知道某些思科代理(也可能是其他)需要任何嘗試的IP地址連接的名稱地址。我們正在爲此制定長期解決方案。

+0

很高興知道您正在處理我們每天面臨的問題:大約40%的客戶使用防火牆,默認情況下會阻止HTTP 1.1。 – DavideB

+1

謝謝你們。我如何知道我的代理是否支持HTTP 1.1?我有webex共享工作的代理,我相信使用HTTP 1.1功能。 – phebbar