Search code examples
.netwcfself-hosting

Bad request, zero length response: where is the WCF log, where to investigate?


I have a WCF self hosted service, which is called by an AJAX JavaScript. In some cases the response is Bad Request and the response length is 0.

What I've done so far:

  • Inspecting req/resp with fiddler: Request seems to be OK, and response is http 400 'Bad Request' length is 0, so no info, no stack trace etc.
  • Trying to set breakpoint in my service implementation: The service method does not even called
  • Trying to set all exceptions in VS menu Debug/Exceptions: No exceptions fired.

  • Now how to investigate toward?

  • Is there any log what self hosted service is writing?
  • Any other idea?

Solution

  • You can enable WCF tracing to track that error down. Just add the following snippet to your application configuration file:

    <configuration>
    
      <system.diagnostics>
    
        <sources>
    
          <source name="System.ServiceModel"
                  switchValue="Verbose, ActivityTracing"
                  propagateActivity="true">
            <listeners>
              <add name="traceListener"
                  type="System.Diagnostics.XmlWriterTraceListener"
                  initializeData= "c:\Traces.svclog" />
            </listeners>
          </source>
    
        </sources>
    
      </system.diagnostics>
    
    </configuration>
    

    This will create a log file containing additional information for every request. You can open the log file with the Service Trace Viewer Tool which provides a nice GUI.