WCF REST Services Troubleshooting Techniques

You can find below several techniques to troubleshoot issues happening with WCF services Failed/Bad requests:

  • IIS Logs: This generates log files that can be viewed using notepad

    • Open IIS Manager and navigate to the level you want to manage. For information about opening IIS Manager, see Open IIS Manager (IIS 7). For information about navigating to locations in the UI, see Navigation in IIS Manager (IIS 7).
    • In Features View, double-click Logging.
    • On the Logging page, in the Actions pane, click Enable to enable logging or click Disable to disable logging.
  • Failed Request Traces: This generates xml files

    • Open IIS Manager and navigate to the level you want to manage. For information about opening IIS Manager, see Open IIS Manager (IIS 7). For information about navigating to locations in the UI, see Navigation in IIS Manager (IIS 7).
    • In the Connections pane, click Sites.
    • In Features View, select the site for which you want to enable trace logging.
    • In the Actions pane, under Configure, click Failed Request Tracing.
    • In the Edit Web Site Failed Request Tracing Settings dialog box, select Enable to enable logging for this site.
    • In the Directory text box, type the path where you want to store the log files or click the browse button () to find a location on the computer. The default is %SystemDrive%\inetpub\logs\FailedReqLogFiles.
  • Fiddler: This tool is a vital one to view the request and response coming from the web service, you can also generate requests from within that tool.
  • WCF Tracing: Steps for traces data collection:
    1. Create a folder c:\temp
    2. Give full control to everyone
    3. Apply the diagnostics elements in configuration file that can be found below 

      This part will go inside <system.servicemodel> section 

      <diagnostics>

      <messageLogging logEntireMessage=”true” logMalformedMessages=”true”

      logMessagesAtServiceLevel=”true” logMessagesAtTransportLevel=”true”

      maxSizeOfMessageToLog=”26214445″ />

      </diagnostics>

      While this part will be at the end of the web.config file right before the configuration close tag.

      <system.diagnostics><trace autoflush=”true” />

      <sources>

      <source name=”System.ServiceModel.MessageLogging” switchValue=”Verbose,ActivityTracing”>

      <listeners>

      <add type=”System.Diagnostics.DefaultTraceListener” name=”Default”>

      <filter type=”” />

      </add>

      <add name=”ServiceModelMessageLoggingListener”>

      <filter type=”” />

      </add>

      </listeners>

      </source>

      <source name=”System.ServiceModel” switchValue=”Verbose,ActivityTracing”

      propagateActivity=”true”>

      <listeners>

      <add type=”System.Diagnostics.DefaultTraceListener” name=”Default”>

      <filter type=”” />

      </add>

      <add name=”ServiceModelTraceListener”>

      <filter type=”” />

      </add>

      </listeners>

      </source>

      </sources>

      <sharedListeners>

      <add initializeData=”c:\temp\Service.messages.svclog”

      type=”System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″

      name=”ServiceModelMessageLoggingListener” traceOutputOptions=”LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack”>

      <filter type=”” />

      </add>

      <add initializeData=”c:\temp\Service.traces.svclog”

      type=”System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″

      name=”ServiceModelTraceListener” traceOutputOptions=”LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack”>

      <filter type=”” />

      </add>

      </sharedListeners>

      </system.diagnostics>

The most important thing to know is that in case you are getting 400 bad request for a REST service without clear error details and you are sure that the request didn’t get into your WCF method, then there is a high probability that the JSON object passed is having a problem in one of its properties that didn’t allow it to be parsed into .Net classes, I advise to specially double check the DateTime fields and ensure they are having a proper value when passed as part of the JSON object.

Advertisements