开发者

Debugging WCF service library--how to "run" it?

I have the source to two Visual Studio solutions. One is a website that calls a WCF service, 开发者_Go百科and the other solution is a WCF service that compiles into a DLL. The website has the WCF service's binary DLL as a reference.

Here's the problem: when I run the website, an uncaught exception makes its way up from the WCF service.

How do I run the WCF service in Visual Studio so I can set break points in the WCF service? The service project is setup to compile into a DLL and I can't debug a a DLL with break points. What do I need to do to "run" the service in once instance of Visual Studio and trigger the exception from running the website in another instance?

This is my first exposure to WCF.

PS: I tried adding the project of the WCF service to the website's solution and get some error about how I won't be able to debug it because of dependencies the WCF service has, so that doesn't appear to be on option.


You can use WcfSvcHost.exe to host your service and debug it. How is your service hosted? You can also attach to the host process directly while it is running which might be a better solution as the problem may be environmental.


You need a host for your service. In WCF, you have two options:

  • host in IIS/WAS (for IIS6, that only works for HTTP bindings; IIS7/WAS support all bindings)
  • self-host in a console app, Winforms app, NT Service

Or as Andrew already mentioned - for testing/debugging purposes, use the generic WcfSvcHost.exe app that basically does self-hosting in a console app.

If you want to have your own little host, you can add a project to your solution, make it a "Windows Console App", add a reference to your service library project, and then basically have this code:

    static void Main(string[] args)
    {
        using (ServiceHost host = new ServiceHost(typeof(YourWCFService)))
        {
            host.Open();
            Console.WriteLine("Service host running......");

            Console.ReadLine();

            host.Close();
        }
    }

This will create a ServiceHost instance, add your service class inside it, and open the host - now it's ready to receive incoming calls. It needs a bit of configuration, too, to know how and where to listen for requests - but that's basically it.

Marc

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜