简体   繁体   中英

how to debug a program that calls a WCF Service,

I am using Visual Studio 2010. I have a very simple asp.net webpage, I browse and upload an xml file, and I have 2 textboxes for now. In the left box, I show the original xml content, and then, I want to call the WCF service, using the xml as input, and display the result returned in the right box.

Right now, I keep getting an error of "Message Service Queue is not available". I have set the system account for message queue service from google searching.

So now, I need to debug the service. After searching around, I thought attach to process might be a good approach. However, in my collegue's machine, restarting the service is so fast that I cannot stop it and click Debug->Attach to Process->select_exe, and to be honest, it's weird that it doesn't stop at the OnStart function at all...

WCF is hosted as windows service.

Could anyone give me any ideas or hints from your experience and knowledge? Or any other approach that you think might be good in my situation.

Any ideas are appreciated. Great thanks. =)

Modify the service code so that it detects either that it's running from the debugger using the Environment.UserInteractive Property or simply that it's in debug mode ( #ifdef DEBUG ) (rather than release) and then start the program as a console application rather than a service.

For example:

    static void Main()
    {
#ifdef DEBUG
        Application.Run();
#else
        ServiceBase service = new SampleService(); 
        ServiceBase.Run(service); 
#endif
    }

This will allow you to set break points and step into code in one instance of Visual Studio while you run the client code in another.

How is this WCF service hosted? Web Service, Windows Service, Console App, etc? in any case you can debug that app in VS and let your application hit it. For Windows Service you will have to change the code a bit for debugging.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM