To programmatically create endpoints and bindings, you can do this in a service:
ServiceHost _host = new ServiceHost(typeof(TestService), null); var _basicHttpBinding = new System.ServiceModel.basicHttpBinding(); //Modify your bindings settings if you wish, for example timeout values _basicHttpBinding.OpenTimeout = new TimeSpan(4, 0, 0); _basicHttpBinding.CloseTimeout = new TimeSpan(4, 0, 0); _host.AddServiceEndpoint(_basicHttpBinding, "http://192.168.1.51/TestService.svc"); _host.Open();
You can also define several endpoints in your service configuration and choose which one will dynamically connect at runtime.
In the client program, you will do the following:
basicHttpBinding _binding = new basicHttpBinding(); EndpointAddress _endpoint = new EndpointAddress(new Uri("http://192.168.1.51/TestService.svc")); TestServiceClient _client = new TestServiceClient(_binding, _endpoint); _client.BlahBlah();
Mohammad Sepahvand
source share