Grentley
Grentley

Reputation: 437

How to update client endpoint binding in code

I have a question about modifying client endpoint binding in code. I have added a web service reference and created a client endpoint binding for it. In web.config I a binding set to basic https, which I want to change it to ex. http, which I have specified in web.config under the name "basicHttpBinding". When I create the instance of the web service reference, there is no way of using address and binding as there is not constructor that takes such arguments.

  <endpoint address="http://localhost/LocalService/SendRequest.asmx"
    binding="basicHttpsBinding" bindingConfiguration="basicHttpsBinding"
    contract="LocalService.SendRequest" name="LocalServiceClient" />

Any advice how to solve this problem would be appreciated.

Cheers!

Upvotes: 2

Views: 2649

Answers (2)

Johann
Johann

Reputation: 12408

var binding = new System.ServiceModel.BasicHttpBinding() { Name = "LocalServiceClient", Namespace = "LocalService.SendRequest" };
var endPoint = new System.ServiceModel.EndpointAddress("http://localhost/LocalService/SendRequest.asmx");
var client = new ServiceClient(binding, endPoint);

Upvotes: 2

jaro
jaro

Reputation: 249

If I understood correctly, this is what you are looking for:

var x = new ServiceClient();
x.Endpoint.Binding = new BasicHttpBinding("optional configuration name");

Upvotes: 1

Related Questions