开发者

Host WCF service through console app

This is开发者_JAVA技巧 probably an easy solution.

I have created the simplest WCF host in a project like this

    static void Main(string[] args)
    {
        using (ServiceHost host = new ServiceHost(
           typeof(AmphoraService.ConsignmentService.Consignment)))
        {
            host.Open();
            Console.WriteLine("Consignment Service Activated! Press <Enter> to terminate " +
               "the Host application.");
            Console.WriteLine();
            Console.ReadLine();
        }
    }

I have supplied the configuration in the app.config file.

When pressing F5 in Visual Studio it runs successfully. The text is displayed in the console window and "netstat -a" shows that port 808 is listening (its a nettcp binding)

However, when I exit Visual Studio and try to click on the bin\debug***.exe file, a console window appears but nothing happens! And "netstat -a" shows that port 808 is NOT listening.

What am i overlooking?


If nothing happens, its likely that the program is sitting on the host.Open() line. Try attatching visual studio to that instance (using Debug > attatch to process).

You can also try waiting a little while and see if you get an exception such as a timeout or something, its possible that something is going wrong when the ServiceHost is trying to instansiate your service object

Perhaps some resource gets locked when you run it the first time (in visual studio)? what if you reboot and run the exe from explorer first?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜