I have a WCF service and I am trying to consume it through a WCF client Library in my web application. For this purpose I created a Console Application, added service reference and tried the following code in Program.cs file inside "main" function.

var factory = new ChannelFactory<IDateTime>("BasicHttpBinding_IDateTime");
var clientChannel = factory.CreateChannel();
var datetime= clientChannel.GetDateTime();

This code works fine. I added a new class (ProxyClient) in the same console application and create a function (GetDateTime) inside the new class and wrote the same code in the function. I added my wcf library reference to my web application and tried to call GetDateTime function through ProxyClient's object But I always get an error on "var factory = new ChannelFactory("BasicHttpBinding_IDateTime")" the error is

Error Message "Could not find endpoint element with name 'BasicHttpBinding_IDateTime' and contract 'DateTimeService.IDateTime' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element"

I am wondering why this is so.

ChannelFactory<IService1> factory = null;
BasicHttpBinding binding = new BasicHttpBinding();

binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
binding.MessageEncoding = WSMessageEncoding.Mtom;

EndpointAddress address = new EndpointAddress(newsiteUrl);
factory = new ChannelFactory<IService1>(binding, address);
IService1 channel = factory.CreateChannel();
message = channel.Function();
  • It worked though by omitting binding properties assignment. I was wondering why my code worked in Program.cs but not when accessing from other application. – V.B Aug 8 '13 at 10:26
  • you have to pass endpoint url with binding – Rajesh Joshi Aug 8 '13 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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