简体   繁体   中英

How to create Channel Factory

Hi I'm trying to call a WCF service from within console application, and return this:

Unhandled Exception: System.InvalidOperationException: The underlying channel factory could not be created because no Binding was passed to the ChannelFactory.

My code:

EndpointAddress address = new EndpointAddress("http://xx.xx.xx.xx:xxxxxx/xxxx/FormulationService");

var servis = new ChannelFactory<IFormulasyonHost>().CreateChannel(address);
((IServiceChannel)servis).Open();

if (args[0].ToString() == "-update")
{
   if (args[1].ToString() == "all")
   {
      servis.UpdateAll();
      ((IServiceChannel)servis).Close();
   }
}

Assuming the basic binding is used

var address = ...
var binding = new BasicHttpBinding();

var servis = new ChannelFactory<IFormulasyonHost>(binding,address)
    .CreateChannel();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM