Inline WSHttpBinding configuration

Is it possible to configure web service bindings for web-service client objects directly from the source code (aside from config file)?

Tagged:

Best Answer

  • Yes. It is possible to configure web-service bindings for web-service client objects not only with the help of a configuration file but also directly in the source code.

    Here is an example of a WSHttpBinding configuration for the Token Management service:

    WSHttpBinding binding = new WSHttpBinding();

    binding.Security.Mode = SecurityMode.Transport;

    binding.SendTimeout = TimeSpan.FromMinutes( 1 );

    binding.OpenTimeout = TimeSpan.FromMinutes( 1 );

    binding.CloseTimeout = TimeSpan.FromMinutes( 1 );

    binding.ReceiveTimeout = TimeSpan.FromMinutes( 10 );

    binding.AllowCookies = false;

    binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;

    binding.MessageEncoding = WSMessageEncoding.Text;

    binding.TextEncoding = System.Text.Encoding.UTF8;

    TokenManagement_1Client client =

    new TokenManagement_1Client(binding, new EndpointAddress("https://api.rkd.reuters.com/api/TokenManagement/TokenManagement.svc/Anonymous"));

    And if you need to set up a proxy server for your application you can do this by adding corresponding lines to the binding object:

    binding.ProxyAddress = new Uri("http://proxyhost.com:8080");

    binding.UseDefaultWebProxy = false;

    binding.BypassProxyOnLocal = false;