Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP proxy + WCF netMessagingBinding + Service Bus

Need help with configuring HTTP Proxy while using netMessagingBinding to connect to Service Bus endpoint. I have an Internet access through the proxy server. When I try to connect to the WCF Service hosted on a worker role on Azure through Service Bus endpoint I get exception that the application cannot connect to the remote endpoint. When I do the same thing through direct internet access everything works perfectly.

like image 740
Azat Avatar asked Jun 06 '26 19:06

Azat


1 Answers

Proxy servers can be tricky depending on the type of proxy. Try changing the settings of your web.config/app.config to enable proxy support:

Detect automatically:

  <system.net>
    <defaultProxy enabled="true" useDefaultCredentials="true" />
  </system.net>

Define proxy url:

  <system.net>
    <defaultProxy enabled="true" useDefaultCredentials="true" />
      <proxy autoDetect="True" proxyaddress="http://..."/>
    </defaultProxy>
  </system.net>

Custom credentials:

  <appSettings>
    <add key="ProxyUser" value="" />
    <add key="ProxyPassword" value="" />
    <add key="ProxyDomain" value="" />
    <add key="ProxyUrl" value="" />
  </appSettings>
  <system.net>
    <defaultProxy enabled="true">
      <module type="CustomProxyCredentials.ProxyBridge, CustomProxyCredentials"/>
    </defaultProxy>
  </system.net>

namespace CustomProxyCredentials
{
    public class ProxyBridge : IWebProxy
    {
        public ICredentials Credentials
        {
            get { return new NetworkCredential(ConfigurationManager.AppSettings["ProxyUser"], ConfigurationManager.AppSettings["ProxyPassword"], ConfigurationManager.AppSettings["ProxyDomain"]); }
            set { }
        }

        public Uri GetProxy(Uri destination)
        {
            return new Uri(ConfigurationManager.AppSettings["ProxyUrl"]);
        }

        public bool IsBypassed(Uri host)
        {
            return false;
        }
    }
}

Connectivity mode:

Microsoft.ServiceBus.ServiceBusEnvironment.SystemConnectivity.Mode = Microsoft.ServiceBus.ConnectivityMode.Http;

Anyways, configuration should be sufficient in order for this to work correctly.

like image 163
Sandrino Di Mattia Avatar answered Jun 10 '26 14:06

Sandrino Di Mattia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!