.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

Home >> Articles >> WCF >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Debugging a WCF Service : in a spark

Posted By:Gaurav Arora       Posted Date: August 22, 2009    Points: 25    Category: WCF    URL: http://www.dotnetspark.com  

Debugging a WCF Service

Following are the 3-different ways to start debugging a WCF service:
  • When you are debugging a client process that calls a service. Here debugger steps into the service also service does not have to be in the same solution as your client application.
  • When you are debugging a client process that requests to a service and here service must be a part of your solution.
  • When you are using Attach to Process to attach to currently running service. Here debugging begins inside the service.

    Debugging with Visual Studio 2008

    Using Visual Studio 2008, one can step into a WCF service. One can hit break points inside the WCF service, if the WCF service is in the same solution as the client.

    For stepping to work, you must have debugging enabled in the app.config or Web.config file we will discuss later on the limitation and how to enable debugging.

    To step into a WCF Service
  • First you need to create a Visual Studio solution that contains both the WCF client and WCF service projects.
  • Now from Solution Explorer, right-click the WCF Client project and then click Set as Startup Project.
  • Then enable debugging in the app.config or web.config file
  • Mark a breakpoint at the location in the client project where you want to start stepping (just before the WCF service call).
  • Now, Run to the breakpoint, then begin stepping. The debugger will step into the service automatically.

    Limitations of Debugging a WCF Service

    1.Stepping Into a Service

    The following conditions should be met when you start To step into a service from a client applications:

  • Service must be called bys using a synchronous client object.
  • One-way contract operation is not allowed.
  • Debugging must be enabled

    2.Stepping Out of a Service

    The limitations are the same as described the above, in addition, here the debugger must be attached to the client. 

    This is because while you are debugging a client and step into a service, the debugger remains attached to the service whether you started the client by using Start Debugging or attached to the client by using Attach to Process.
    But while you are debugging by attaching to the service, the debugger is not yet attached to the client. In that case, you must first use Attach to Process to attach to the client manually.

    Debugging must be enabled

    3.Automatic Attach to a Service

    Automatically attaching to a service has the following limitations:

  • In this case the service must be part of the solution you are debugging.
  • The service must be hosted. Which means it may be part of a Web Site Project (File System and HTTP), Web Application Project (File System and HTTP), or WCF Service Library project. WCF Service Library projects can be either Service Libraries or Workflow Service Libraries.
  • WCF client must be invoked the service.
  • Debugging must be enabled

    Enabling Debugging a WCF Service

    Use following piece of lines in web.config or asp.config file(s):


    Note: In case when you use Attach to Process on a service, the debug code is automatically added to the .config file. 

  • How to Debug a Self-Hosted WCF Service?

    In simple words WCF service which does not run inside IIS, WCF service Host or ASP.NET Development Server is know as Self-Hosted Service.

    To debug such services we need to configure Visual Studio to launch both client and server when you choose Start Debugging on the Debug menu.

    How to start both client and host from Visual Studio?

  • Need to create a Visual Studio solution pertaining both the client and server projects.
  • Now configure the solution to start both client and server :
    a. From Solution Explorer, right-click the solution name.
    b. Click Set Startup Projects.
    c. In Solution from Properties dialog box, select Multiple Startup
    d. Click Action and choose Start from the Multiple Startup Projects grid, 
    on the line that corresponds to the server project also on the line that 
    corresponds to the client project, click Action and choose Start.
    e. Finally click OK.

  •  Subscribe to Articles


    Further Readings:


    No response found. Be the first to respond this post

    Post Comment

    You must Sign In To post reply
    Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

    Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend