Debugging in a WCF Service

So, we are launching the SOA architecture. I have a service that I am trying to debug in a call that comes from a WinForms application in another solution.

In this winforms application, I correctly referenced the localhost service in app.config, and now I want to start the WCF service instance to set a breakpoint and execute it.

When I go to the service, I directly click on the project, go to the properties, and in the section "Start action" I select the .exe file in the bin / debug / services directory. Then I save, compile and hit F5 to start the instance. I get this error:

enter image description here

What should I do?

+4
source share
4 answers

you need to host the service in the process and then debug it from there. It can be as simple as writing a console application to host the service, or writing a Windows service to host the service, or an application for Windows forms, or host it in IIS.

you can place in a console application like this:

static void Main(string[] args) { using (ServiceHost host = new ServiceHost(typeof(YourNamespace.YourServiceInterface))) { host.AddServiceEndpoint(typeof( YourNamespace.YourServiceInterface), new NetTcpBinding(), "net.tcp://localhost:9000/YourService"); host.Open(); Console.WriteLine("Press <Enter> to terminate the Host application."); Console.WriteLine(); Console.ReadLine(); } } 

This article shows how to host a Windows service. I would recommend adding

 Debugger.Launch(); 

as the first line in the OnStart method so that you can attach a debugger when the service starts. This will help debug any startup problems. Otherwise, you can simply select AttachToProcess from the Debug menu and connect to a running Windows service.

you need to add using System.Diagnostics to use the Debugger.Launch(); method Debugger.Launch();

+6
source

You need to install the service that you are creating locally as a Windows service, and then connect to it.

+1
source

Does the service work under IIS or on its own? In any case, as soon as the service is started, you can connect to it by going to Debug-> Attach Process.

If you are running IIS, you need to look for the w3wp.exe process (IIS 7). Please note that in order to join this process, you most likely will have to run VS as an administrator. If you are using an older version of IIS, the process is called something like aspnet_XXX.

Once you are connected, you can place your breakpoints and debug if necessary.

+1
source

Well, you got this error when trying to start / debug a class library project, so make sure your services project is not like that.

If you want to simplify the task (and there is no problem with the infrastructure of infrastructure) in order to run / debug from VS, make it a WCF service application project that hosts services on a website, such as the project: https: // dl-web. dropbox.com/get/Photos/web/wcfserviceapp.png?w=44e8c6ed

Thus, you can start the service in your solution, and then start the winforms application from your solution, then you can go to the "Debug / Attach to process ..." menu and look for the service URL and port: https: // dl -web.dropbox.com/get/Photos/web/debugattachtoprocess.png?w=8c917c28

I hope this helps, if not please clarify, in order to have a clearer idea of ​​what projects you have, how your decision and other useful information.

0
source

All Articles