Hi All,
I am trying connect to a web service endpoint from my code as below:
BasicHttpBinding binding = new BasicHttpBinding(); EndpointAddress remoteAddress = new EndpointAddress("<endpoint address>"); binding.Name = "ServiceSOAP"; binding.AllowCookies = false; ServiceClient client = new ServiceClient(binding, remoteAddress);
Using the above way I can connect to the endpoint and carry out the tasks.
My query is:
" Instead of hard coding the endpoint address in the code, can it be fetched from the app.config or web.config file.
The config file is as below:
<system.serviceModel> <bindings> <basicHttpBinding> <binding name="NotificationServiceSOAP" /> </basicHttpBinding> </bindings> <client> <endpoint address="http://<endpointaddress>/notificationDispatcher" binding="basicHttpBinding" bindingConfiguration="NotificationServiceSOAP" contract="Notification.NotificationService" name="NotificationServiceSOAP" /> </client> </system.serviceModel>
I tried using the code below to access the endpoint address from within the event receiver but it fails in first line itself on debug, might be it is not able to read the config file.
ClientSection clientSection = (ClientSection)WebConfigurationManager.GetSection("system.serviceModel/client"); ChannelEndpointElement endpoint = clientSection.Endpoints[0]; string endpointStr = string.Format("Address: {0}; Binding: {1}; Contract: {2}", endpoint.Address.ToString(), endpoint.Binding, endpoint.Contract); NotificationServiceClient client = new NotificationServiceClient(endpointStr);
I have also tried using as below but doesn't work inside an event receiver
NotificationServiceClient client = new NotificationServiceClient("NotificationServiceSOAP");
Could you please suggest few options or am I doing anything wrong here!
Thanks in advance.