KallDrexx
KallDrexx

Reputation: 27803

How do I investigate WCF giving 400 bad request over GET?

The following WCF endpoint works just fine with the WCF test client:

[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Xml,
        BodyStyle = WebMessageBodyStyle.Bare,
        UriTemplate = "listflaggedassets/{platform}?endpoint={endpoint}&pid={portalid}&processCode={processCode}&index={index}&limit={limit}")]
AssetList ListFlaggedAssets(short processCode, string platform, string endpoint = "null", string portalId = "null", int index = 0, int limit = 12);

However, when I attempt to navigate to the URL http://localhost/DigitalREST/XosAssets.svc/listflaggedassets/SEC?endpoint=superfan&pid=0&processCode=0&index=0&limit=20 I get a 400 bad request.

I can't seem to find any way to figure out WHY i'm getting a bad request, and attaching to IIS for debugging doesn't break on any exceptions.

How can I investigate the cause of a bad request?

Upvotes: 7

Views: 8568

Answers (4)

Mubashar
Mubashar

Reputation: 12658

You can try fiddler and also try the svcTracer which may give you lot of debugging information on the top of it you can also use includeExceptionDetailInFaults=true flag on the server but its important to know that its not always right to send this information to the client specially if client is an external entity. With this warning following is the hint how to use it.

<serviceBehaviors>
    <behavior name="ServiceBehavior">
    ....
        <serviceDebug includeExceptionDetailInFaults="true" />
    ....
    </behavior>
</serviceBehaviors>

Happy debugging :)

Upvotes: 0

Learner
Learner

Reputation: 447

One reason could be, which I encountered:

I was trying to request using the URL with querystring but httpbinding wasn't in place in config file and in result I was getting 400-Bad request error.

Upvotes: 0

Rajesh
Rajesh

Reputation: 7876

The best way would be to install Fiddler and capture your request along with enabling Tracing on your service.

Also try to remove the BodyStyle which you specified in the WebGet attribute and see if it would work.

Upvotes: 0

Jim Schubert
Jim Schubert

Reputation: 20357

You could enable tracing and use Service Trace Viewer

Drop this into your app.config (logging sources taken from this answer):

<system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true" >
        <listeners>
          <add name="xml"/>
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add name="xml"/>
        </listeners>
      </source>
      <source name="myUserTraceSource"
              switchValue="Information, ActivityTracing">
        <listeners>
          <add name="xml"/>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="xml"
           type="System.Diagnostics.XmlWriterTraceListener"
           initializeData="TraceLog.svclog" />
    </sharedListeners>
  </system.diagnostics>

Then, open the TraceLog.svclog in Service Trace Viewer. It may not tell you exactly what's going on, but it will provide details about the traffic and the exception itself.

You may also want to check the exceptions you have enabled in the debugger. In Visual Studio, go to Debug -> Exceptions and check that you have the correct framework checked.

Upvotes: 6

Related Questions