2015-10-20 81 views
0

嗨,我試圖從控制檯應用程序中調用WCF服務,返回此:如何創建通道工廠

未處理的異常:System.InvalidOperationException:底層通道工廠無法創建,因爲沒有綁定已傳遞給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(); 
    } 
} 

回答

0

假設基本結合使用

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

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