0

I am have a simple hosting WCF service side-by-side with ASP.NET and have a difficult time to debug/step-in to the service. Below are the files. Thanks in advance!

Web.config

  <system.web>
    <compilation debug="true" targetFramework="4.5.2"/>
    <httpRuntime targetFramework="4.5.2"/>
  </system.web>

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="mexBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

    <services>
      <service name="WCF_TestService.TestService" behaviorConfiguration="mexBehavior">
        <endpoint address="" binding="basicHttpBinding" contract="WCF_TestService.ITestService"></endpoint>

        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/" />
          </baseAddresses>
        </host>
      </service>
    </services>

  </system.serviceModel>

ITestService.cs

namespace WCF_TestService
{
    [ServiceContract]
    public interface ITestService
    {
        [OperationContract]
        string GetMessage(string name);
    }
}

TestService.svc.cs

The breakpoint is set on return and the prompted message is The breakpoint will not currently be hit. No symbols have been loaded for this document

namespace WCF_TestService
{
    public class TestService : ITestService
    {
        public string GetMessage(string name)
        {
            return $"Hello {name}";
        }
    }
}

Client

The client is the console application.

namespace Client
{
    class Program
    {
        static void Main(string[] args)
        {
            ServiceProxy.TestServiceClient client = new ServiceProxy.TestServiceClient();
            Console.WriteLine(client.GetMessage("John Smith"));
            Console.ReadLine();
        }
    }
}
Jason
  • 1,680
  • 3
  • 13
  • 16

2 Answers2

1

Per your comment about both projects in the same solution and WCF not being self hosted, you will need to configure your solution to have multiple startup projects.

In the solution explorer, select the solution, right click and select properties. Expand the Common Properties selection in the pop-up and click Startup Project. Click Multiple Startup Projects and select your projects and build action. Set appropriate order as well (WCF first in this case)

Also do not forget to change your endpoint address of your console app to point to the appropriate IIS port that your wcf project is running on when running, it may be in your best interest to setup configuration transforms for debug, and prod so you are not constantly switching these out in your config.

If the only reason you created the console project was to interact with your WCF service for testing then I would urge you to use WCF Test CLient instead. It should be installed by default on any VS instance.

Travis Acton
  • 4,292
  • 2
  • 18
  • 30
  • Thanks Travis, that will do the trick. Another question is why the normal attach the process won't work for this kind the project setup? – Jason Aug 23 '17 at 21:08
  • @JasonTang Normal attach should work just fine if your code is deployed to local IIS but you have to change the build path to your IIS bin directory rebuild, then run so everything is perfectly up to date. I have always found it much more flexible/less touchy to do it this way, especially when you are mid development on a project. – Travis Acton Aug 23 '17 at 21:33
0

Maybe this response is the same of this topic.

How to debug WCF programs

  1. You need to attach the debugger to the process that your wcf service is running in.

    • If in iis you need to attach to the corresponding w3p.exe process.

    • If in a stand alone app or windows service, attach to the name of your exe.

  2. In Visual Studio, on the debugger menu, there is an "attach to process". Open the relevant code, set a breakpoint, and call the service causing that code path to execute.

Outside of debugging, using .net tracing with switchable levels is a good way to get insight to what's going on. I typically setup sys internals debugview to color highlight errors and warnings and constantly have it running while running code or tests. Colored lines out of my peripheral vision while working finds issues.

Try run Visual Studio with a system administrator. Maybe you atached the wrong process, or the version running is not the debug version.

ALTERNATIVE

You can click with right button in both projects, and click in "Debug" -> "Start New Instance". The Visual Studio start both projects in Debug mode.

Rafael Marcos
  • 254
  • 1
  • 8
  • I have tried to attach `w3wp.exe` process but no luck. – Jason Aug 23 '17 at 19:49
  • Try run Visual Studio with a system administrator. Maybe you atached the wrong process, or the version running is not the debug version. You can click with right button in both projects, and click in "Debug" -> "Start New Instance". The Visual Studio start both projects in Debug mode. – Rafael Marcos Aug 24 '17 at 16:55