Sunday, October 9, 2011

Enable WCF tracing/logging using SvcConfigEditor and view logs using SvcTraceViewer

This post will show how easy it is to enable WCF tracing through SvcConfigEditor and view the logs using SvcTraceViewer. The sample code can be downloaded from

SvcConfigEditor

  1. SvcConfigEditor.exe can be opened from VS 2010 ad displayed below

    image

  2. Open the Web.Config of the WCF service from the File Menu.
  3. Under Diagnostics node, Tracing and MessageLogging can be configuredimage
  4. Click on Enable MessageLogging and Enable Tracing. Default Log/Trace Level, Listener and Log file will be configured as displayed belowimage

Saturday, October 8, 2011

How to call methods from client side using AJAX extensions

We can call methods from client side using AJAX extensions

  1. Static methods in an ASP.net page
  2. Methods of a ASP.net web service

The sample code for this article is at

Static methods in an ASP.net page

In this case the method resides in the Web page. In order to call we need to

  1. Set EnablePageMethods="true" in ScriptManager
  2. The method needs to be public and static
  3. Add [WebMethod] attribute to the method
[System.Web.Services.WebMethod]
public static string GetInformation()
{
     return "Hello from Page Method";
}

From JavaScript we can now call the method as displayed below

<script language="javascript" type="text/javascript">
 
        function GetInfoFromPage() {
            PageMethods.GetInformation(OnSuccess, OnFail);
        }
 
        function OnSuccess(result) {
            alert(result);
        }
 
        function OnFail(result) {
            alert(result.get_message());
        }
    
</script>

 

Methods in an ASP.net Web Service

In this case the method resides in the Web service. In order to call we need to

  1. Add [System.Web.Script.Services.ScriptService] attribute to the Web Service
  2. Add the service reference to the ScriptManager
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class DemoService : System.Web.Services.WebService {
 
    public DemoService()
    {
        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }
 
    [WebMethod]
    public string GetInformation(){
        return "Hello from Web Service method";
    }
    
}

 

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
        <Services>
            <asp:ServiceReference Path="~/DemoService.asmx"/>
        </Services>
</asp:ScriptManager>

From JavaScript we can now call the method as displayed below

<script language="javascript" type="text/javascript">
 
        function GetInfoFromService() {
            DemoService.GetInformation(OnSuccess, OnFail);
        }
 
        function OnSuccess(result) {
            alert(result);
        }
 
        function OnFail(result) {
            alert(result.get_message());
        }
    
</script>