WPF应用程序中的WCF通道工厂超时

问题描述:

我在C#中的WPF应用程序中托管WCF服务。我想从主机本身调用一些初始化函数,所以我使用的是通道工厂。当主机打开时,我可以从另一个应用程序调用WCF服务方法,但是当我在主机中运行下面的代码时,我在Test()方法上超时。WPF应用程序中的WCF通道工厂超时

host = new ServiceHost(typeof(SequencerService), new Uri(address)); 
host.Open(); 

var binding = new NetTcpBinding(SecurityMode.None); 
EndpointAddress endpoint = new EndpointAddress("net.tcp://10.0.0.118:50111/SequencerService"); 
ChannelFactory<ISequencerService> myFactory = new ChannelFactory<ISequencerService>(binding, endpoint); 
ISequencerService mService = myFactory.CreateChannel(); 

Console.WriteLine(mService.Test()); 

我被锁定在最后一行代码上。此外,如果我尝试在控制台应用程序中托管此代码,它工作正常。为什么在WPF窗口应用程序中运行它时有什么不同?

+0

这可能是有益的,包括什么是'测试)发生('。 – gh0st

+0

现在测试只是返回“Hello”字符串 –

我刚找到答案。这似乎是服务必须比在消耗一个单独的线程托管主机I使用:

new Thread(()=>{ 
    host = new ServiceHost(typeof(SequencerService), new Uri(address)); 
    host.Open(); 
}.Start();