Skip to main content

Turning WCF Service into .asmx for debugging

Even though .asmx web services are becoming dinosaurs of the new .NET world of WCF. I missed the simplicity of debugging code right in visual studio without:
  • Creating a client to consume WCF service
  • Attaching w3p.exe process and
  • Adding break points 
One quick solution: Turn WCF service into .asmx service with few lines of code, debug your code with asmx, and turn .asmx off during deployment. 

Detail steps:

1- First take your WCF class and add WebService attribute to it

Code Snippet
  1. /// <summary>
  2. /// Dual mode with .ASMX and WCF
  3. /// </summary>
  4. [WebService(Namespace = "http://www.yourdomain.com/")]

2- Then add WebMethod attribute to a function you want to expose in .asmx

Code Snippet
  1. [WebMethod]
  2. public List<PageController.Page> DualFunction()
  3. {

3- Take the .svc file from your solution - copy and rename the copied file [YourOriginalWCFFile.asmx]. Open up the copied file and rename "ServiceHost" to "WebService" in the .asmx file. You will end up with a file that looks like

<%@ WebService Language="C#" CodeBehind="PathToCode" Class="YourClass" %>

That's it you are done! Now you can add breakpoints in your code and fireup the .asmx file for debugging. You can turn of the .asmx service by removing the WebService and WebMethod attributes to your class and function during deployment. 

Comments

Popular posts from this blog

Processing ASP MVC Web API Requests in Multi-threaded JS Web Worker

Unlike an asynchronous Ajax call, HTML5 Web workers provide an opportunity to run a Multi-threaded JavaScript code in modern browsers that support them . Each worker spawns an isolated thread with dedicated JavaScript Event Loop, Stack and Heap memory. For example a regular Ajax Call to MVC Web API service call goes through the following asynchronous call cycle. The JavaScript Event Loop in this case could be interrupted by events that are being executed on the UI; for instance, a "window.alert", could possibly stop all scripts on the page from executing until a user responds. Replacing the Ajax Call with HTML5 web worker provides a great way to run long running scripts in separate threads so that asynchronous code execution is not interrupted by UI events. Here is the a JavaScript worker implementation of the same MVC Web API call using a JavaScript web worker. Despite the advantages of using a web worker, implementing one requires working with some constr...

Simple and reusable directive for making list elements draggable.

I was working on Angular lists and needed a easy to implement and reusable solution to make list items draggable . I chose to implement the solution as an Angular directive so that I can pass scope references to the new helper controller and execute ng-repeat, as needed, to recreate Dom elements. After adding the helper controller, I was able to make ng-repeat lists in my application draggable by simply adding a custom attribute and passing the Angular collection name. Here is a Plunkr demo  and full GitHub source code .