How can I investigate WCF by giving 400 bad requests via GET?

The following WCF endpoint works great with the WCF testing 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 try to go to the URL http://localhost/DigitalREST/XosAssets.svc/listflaggedassets/SEC?endpoint=superfan&pid=0&processCode=0&index=0&limit=20 , I get 400 bad requests.

I cannot find a way to find out WHY I get a bad request, and binding to IIS for debugging does not break any exceptions.

How can I find out the reason for a bad request?

+7
source share
3 answers

You can enable tracing and use the Service Trace Viewer

Put this in 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 TraceLog.svclog in the Service Trace Viewer. It cannot say exactly what is happening, but it will contain information about the traffic and the exception itself.

You can also check the exceptions that you have included in the debugger. In Visual Studio, go to Debug -> Exceptions and make sure you check the correct structure.

+6
source

The best way would be to install Fiddler and capture your request along with the inclusion of "Tracing" in your service.

Also try removing the BodyStyle that you specified in the WebGet attribute and see if it works.

0
source

One of the reasons I came across:

I tried to request the url using querystring, but the http connection was not in the configuration file, and as a result I got a 400-Bad request error.

0
source

All Articles