7

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?

KallDrexx
  • 27,229
  • 33
  • 143
  • 254
  • It sounds like you don't have WCF registered correctly. If you try this url - what do you get? http://localhost/DigitalREST/XosAssets.svc – tsells Mar 28 '12 at 03:06

4 Answers4

6

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.

Community
  • 1
  • 1
Joseph Yaduvanshi
  • 20,241
  • 5
  • 61
  • 69
  • Thanks. While the logs weren't useful (some internal xml error) It at least answers my question on how to invesitage these WCF errors. Something's fubared either with my local IIS or web.config cause it all works remotely. – KallDrexx Mar 28 '12 at 12:55
  • You can look over [these instructions](http://msdn.microsoft.com/en-us/library/aa751792.aspx) to verify the installation of both ASP.NET and WCF. – Joseph Yaduvanshi Mar 28 '12 at 13:32
0

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.

Learner
  • 447
  • 2
  • 5
  • 15
0

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 :)

Mubashar
  • 12,300
  • 11
  • 66
  • 95
0

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.

Rajesh
  • 7,766
  • 5
  • 22
  • 35