1

I have designed a listener that exposes a LOB application over the service bus. I had to write this listener because our application is protected by a firewall that doesn't allow inbound connection.

The code below is how I initialize my listener using NetTcpRelayBinding and it's working quite well:

var sharedSecretServiceBusCredential = new TransportClientEndpointBehavior()
{
    TokenProvider = TokenProvider.CreateSharedSecretTokenProvider("listener", "MySecret")
};

var address = ServiceBusEnvironment.CreateServiceUri("sb", "MyNamespace", "CrmConnectorService");

ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Tcp;

_host = new ServiceHost(typeof(CrmConnectorService), address);

var binding = new NetTcpRelayBinding()
{
    CloseTimeout = TimeSpan.FromMinutes(5),
    OpenTimeout = TimeSpan.FromMinutes(5),
    ReceiveTimeout = TimeSpan.FromMinutes(5),
    SendTimeout = TimeSpan.FromMinutes(5)
};
binding.Security.RelayClientAuthenticationType = RelayClientAuthenticationType.RelayAccessToken;

var endpoint = _host.AddServiceEndpoint(typeof(ICrmConnectorService), binding, address);

var serviceRegistrySettings = new ServiceRegistrySettings(DiscoveryType.Private);

_host.Description.Endpoints[0].Behaviors.Add(serviceRegistrySettings);
_host.Description.Endpoints[0].Behaviors.Add(sharedSecretServiceBusCredential);

_host.Open();

However, we have a new requirement: I need to be able to support proxy. My understanding is that NetTcp does not support proxies (please correct me if I'm wrong) therefore I need to be able to fallback on HTTP (I still want to use TCP if possible and only fallback to HTTP if necessary). I did some research and discovered that ServiceBus supports "AutoDetect" connectivity mode that "probes whether either connectivity option is available for the current network environment. If both are available, the system will choose TCP by default". This is exactly what I want. However, I don't know how to improve my code to support this feature.

Obviously I will change:

ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Tcp;

with

ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.AutoDetect;

but I don't know what else I need to change. I am guessing that I somehow need to configure another binding in addition to NetTcp but how do I do that?

1 Answer 1

1

AutoDetect is the default connectivity mode -- you don't need to add anything. And it should work with a proxy.

3
  • Indeed AutoDetect is the default but what I am really trying to figure out is how do I configure both bindings? In the code sample I provided you can see that I configure the TCP binding, what I want to know is how do I configure the HTTP binding IN ADDITION to the TCP binding?
    – desautelsj
    Aug 20, 2014 at 15:09
  • You don't need to configure another binding to get it to work using HTTP connectivity mode. NetTcp binding will revert to use HTTP if it cannot use TCP if the connectivity mode set is AutoDetect.
    – TheDude
    Aug 20, 2014 at 23:16
  • ok, I think I'm following what you're saying. But what about configuring the HTTP binding? What if my proxy requires authentication and I need to specify username and password for example? I'm guessing it will use the default proxy settings that are configured in IE's "Internet options", but what if I don't want to rely on those default values and I want to specify my own user+pwd?
    – desautelsj
    Aug 25, 2014 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.