Showing posts with label Debugging. Show all posts
Showing posts with label Debugging. Show all posts

Thursday, 6 February 2014

Debugging WCF service using SvcTraceView on application server

Debugging web services can be pain, specially when they are hosted on a application server within a SharePoint farm. There are several ways one can debug web services though, e.g. using a visual studio remote debugger but what if it doesn't hit your web services breakpoints or your network administrator do?

Easiest way to figure out what's wrong with web services is to use SvcTraceViewer.exe e.g. why my code not able to find the hosted service or if the problem is with service account authentication.

Not so difficult to set it up, all you need to do is to add a some tag in your hosted WCF services and then open the SvcTraceViewer to view the created file.

Step-1:
Find hosted WCF service's web.config and add following tag to it within configuration tag. It will recycle the application pool of hosted service itself when you will save changes to web.config file.


<configuration>
<system.diagnostics>
    <trace autoflush="true" />
    <sources>
            <source name="System.ServiceModel" 
                    switchValue="Information, ActivityTracing"
                    propagateActivity="true">
            <listeners>
               <add name="sdt" 
                   type="System.Diagnostics.XmlWriterTraceListener" 
                   initializeData= "WcfConfigExample.e2e" />
            </listeners>
         </source>
    </sources>
</system.diagnostics>
</configuration>


Step-2:
Find SvcTraceViewer.exe within installed Visual studio files, location might change depending on version of VS, however since I am using VS 2010 ultimate so I find EXE file at,

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools

In some cases you will need to open the EXE file as administrator.

Step-3:
Do something to trigger WCF services and check folder where web.config file exists as that's where it will create "SdrConfigExample.e2e" log file, once you find it. just open the SvcTraceViewer.exe file.

Step-4:
Press Ctrl + O keys; Navigate to SdrConfigExample.e2e file to load log trace file in viewer.

Step-5:
Search for specific terms using Ctrl + F or just go through logs. You can also add custom logs to your WCF service and find them in here to figure out where exactly your code is getting exception at, You can find more about Trace Viewer at, http://msdn.microsoft.com/en-us/library/aa751795(v=vs.110).aspx

Tuesday, 3 September 2013

How to check Assembly related errors using Fusion Log utility


One of most annoying exceptions we developer get is assembly found doesn't match with loaded assembly, even though we put right assembly in GAC. There can be tens of reason as why assembly loaded doesn't match and that's where fusion log utility helps.

In order to use this utility you need to have installed Microsoft SDKs or it gets installed when you installed visual studio. I have installed Visual Studio 2008 on Windows Server 2003 so my guide will be based on it.

Open Visual Studio 2008 command prompt and navigate to directory

C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin>

Now type fuslogvw.exe and you will see a windows appears as shown below,




Click on settings and check box Log all binds to disk as shown, you can also select "Custom log path" but make sure directory exists.

If your log was disabled before then you might need to do a IIS reset to make it start working. (it took mine around 30 minutes to pick up errors because of unknown reasons).

You will see logs as shown in picture below,


And clicking on any log will open it in browser as it's a html file, as shown below.



Make sure to disable log afterwords as otherwise they will take a lot of space within short time.