Recently I was working on an App Fabric Application which was connecting to App Fabric Service bus while hosted inside IIS. The application was working fine while connecting with App Fabric Service Bus, when my machine was located in a network where there was no proxy. However when my machine was moved into a network where there was proxy server, the same application returned the following error:

Unable to reach watchdog.servicebus.windows.net via TCP (9351, 9352) or HTTP (80, 443) 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ServiceModel.CommunicationException: Unable to reach watchdog.servicebus.windows.net via TCP (9351, 9352) or HTTP (80, 443)

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[CommunicationException: Unable to reach watchdog.servicebus.windows.net via TCP (9351, 9352) or HTTP (80, 443)]
Microsoft.ServiceBus.NetworkDetector.ChooseConnectivityModeForAutoDetect(Uri uri) +182
Microsoft.ServiceBus.TcpRelayTransportBindingElement.BuildInnerBindingElement(BindingContext context) +771
Microsoft.ServiceBus.TcpRelayTransportBindingElement.BuildChannelListener(BindingContext context) +37
System.ServiceModel.Channels.BindingContext.BuildInnerChannelListener() +63
System.ServiceModel.Channels.MessageEncodingBindingElement.InternalBuildChannelListener(BindingContext context) +67
System.ServiceModel.Channels.BinaryMessageEncodingBindingElement.BuildChannelListener(BindingContext context) +48
System.ServiceModel.Channels.BindingContext.BuildInnerChannelListener() +63
Microsoft.ServiceBus.HttpRelayTransportBindingElement.BuildChannelListener(BindingContext context) +308
System.ServiceModel.Channels.BindingContext.BuildInnerChannelListener() +63
System.ServiceModel.Channels.MessageEncodingBindingElement.InternalBuildChannelListener(BindingContext context) +67
System.ServiceModel.Channels.TextMessageEncodingBindingElement.BuildChannelListener(BindingContext context) +48
System.ServiceModel.Channels.BindingContext.BuildInnerChannelListener() +63
System.ServiceModel.Channels.Binding.BuildChannelListener(Uri listenUriBaseAddress, String listenUriRelativeAddress, ListenUriMode listenUriMode, BindingParameterCollection parameters) +125
System.ServiceModel.Description.DispatcherBuilder.MaybeCreateListener(Boolean actuallyCreate, Type[] supportedChannels, Binding binding, BindingParameterCollection parameters, Uri listenUriBaseAddress, String listenUriRelativeAddress, ListenUriMode listenUriMode, ServiceThrottle throttle, IChannelListener& result, Boolean supportContextSession) +337
System.ServiceModel.Description.DispatcherBuilder.BuildChannelListener(StuffPerListenUriInfo stuff, ServiceHostBase serviceHost, Uri listenUri, ListenUriMode listenUriMode, Boolean supportContextSession, IChannelListener& result) +724
System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) +1319
System.ServiceModel.ServiceHostBase.InitializeRuntime() +60
System.ServiceModel.ServiceHostBase.OnBeginOpen() +27
System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +50
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +318
System.ServiceModel.Channels.CommunicationObject.Open() +36
System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +184
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +615

I tried to use App Fabric Server Sample Application iishostedcalculatorservice which resulted the same error.

I tried to modify web.config with http/nettcp bindings however none of the binding settings was working with proxy. I used another App Fabric SDK sample ECHO app which worked with both http and tcp settings which indicate that the command line application could connect to Service Bus however the application hosted in IIS & Application Pool was not able to connect to server bus. So most of the attention went towards Application Pool. 

........

After some digging here and there, I found that the application was running inside IIS Application Pool (based on .net 4.0) however the Application Pool was not able to use access credentials properly to pass proxy server, which ultimately cause this error. I was able to solve this problem using the following steps:

  1. Added a new AppPool based on 4.0. Be sure to use  proper credentials to it. If machine is domain joined then please use your Active Directory credentials and if machine is not domain joined then use local machine admin credentials (servername\username + Pwd)


  1. After it you can setup your IIS application to use newly create Application Pool
  2. Please don't forget to reset IIS otherwise new settings will not take affect

After above these changes, the application worked without any further hitch.