如何创建Channel Factory

问题描述 投票:0回答:1

嗨,我正在尝试从控制台应用程序中调用WCF服务,并返回:

未处理的异常:System.InvalidOperationException:无法创建基础通道工厂,因为没有将Binding传递给ChannelFactory。

我的代码:

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();
   }
}
c# wcf
1个回答
0
投票

假设使用了基本绑定

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

var servis = new ChannelFactory<IFormulasyonHost>(binding,address)
    .CreateChannel();
© www.soinside.com 2019 - 2024. All rights reserved.