Gern Blanston
Gern Blanston

Reputation: 42660

IIS hosted WCF rest service getting 400 error, is URL too long?

I have a WCF rest\webHttpBinding service that is returning from browser (IE,Chrome) :

Bad Request - Invalid URL - 
HTTP Error 400. The request URL is invalid.

The service uses GET (we probably should change to POST but originally we were told the max url would be 50 characters) and I'm curious as to what the problem is...just for my own piece of mind.

We had this issue previously with a url that was over 300 chars so in the web config we set the maxUrlLength, as below.

  <system.web>
    <compilation targetFramework="4.0" />
    <httpRuntime maxUrlLength ="5000" maxQueryStringLength="2048" />
  </system.web>

This was working when did this update but now it does not seem to work, anything over 300 we get a 400 error.

I think that something else is blocking the request now. I say this b/c previously we had info in our own log file and in the wcf 'diagnostics' log file. Now neither of those are written to ... its like the service is not even being involved. And previously if I hit the service on the server itself I would get this error

The length of the URL for this request exceeds 
 the configured maxUrlLength value.

But I no longer get that error.

We don't 'own' the server, that is some else is the admin and things have changed on it before without us being informed.

I look around on SO but most mentioned setting up diagnostics. There was Http.sys registry settings for IIS, which I got from http://social.msdn.microsoft.com but nothing seem to be relevant. Also add a section but I believe should be good enough (as per SO answers)

Any ideas what might be happening?

Thanks!

.net 4.0 , iis 7, windows server 2008

EDIT: And to add I can update the maxUrlLength to something small, say 50, and use a URL of > 50 and it fails but fails with the "The length of the URL for this request exceeds the configured maxUrlLength value." message. So I'm feeling something else, before it gets to the WCF service, is causing the issue.

Upvotes: 1

Views: 1843

Answers (2)

Diamond Reed
Diamond Reed

Reputation: 1

Your problem is you're not using a query string, but a path. A path has a maximum length of 255.
Difference between query string and a path to call wcf as below
using path = http://testservice/service.svc/callfunction/testdata
by using query string
using querystring - http://testservice/service.svc/callfunction?param1=testdata

Upvotes: 0

Sean Gough
Sean Gough

Reputation: 1711

I had this same issue and thanks to this answer was able to resolve it by adding the following:

<system.web>
  <httpRuntime maxUrlLength="500" />
</system.web>

Upvotes: 1

Related Questions