3

I have a WCF service hosted on http://localhost:8080, and a web application on http://localhost:82. I have Windows 7 64-bit and IIS 7.5.

The pages in the web app makes AJAX requests to the WCF service using jQuery.

In IE, the service calls perform fine. In Firefox, I get a 405 Method Not Allowed error. The service calls that the web application makes from the ASP.NET code-behind always succeed.

Other developer's builds are having the same problem. I initially thought it had to do with cross-site security restrictions that were introduced in FF 3.5, based on this article: https://developer.mozilla.org/En/HTTP_access_control. However, after adding all the response headers I appeared to need, the problem still occurred.

I've run the aspnet_regiis.exe command, and the WCF ServiceModelReg.exe command as well.

Here is the request that Firefox makes:

OPTIONS http://localhost:8080/ScoutService.svc/Contact_Add HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
Origin: http://localhost:82
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type
Pragma: no-cache
Cache-Control: no-cache

Here is the response from the server:

HTTP/1.1 405 Method Not Allowed
Cache-Control: private
Allow: POST
Content-Length: 1565
Content-Type: text/html; charset=UTF-8
Server: Microsoft-IIS/7.5
Set-Cookie: ASP.NET_SessionId=53pqdbqgtj2cfdvtqrikiewu; path=/; HttpOnly
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Access-Control-Allow-Origin: http://localhost:82
Access-Control-Allow-Methods: POST, GET, OPTIONS
Access-Control-Max-Age: 17280
Access-Control-Allow-Headers: content-type
Access-Control-Allow-Credentials: true
Date: Thu, 15 Sep 2011 15:55:27 GMT

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Service</title>
  </head>
  <body>
    <div id="content">
      <p class="heading1">Service</p>
      <p>Method not allowed.</p>
    </div>
  </body>
</html>

Any ideas?

Tedderz
  • 587
  • 5
  • 15

1 Answers1

2

Firefox sends an OPTIONS request in addition to a POST or GET.

See http://forums.iis.net/t/1160649.aspx for how to fix it.

Edit

The other thing that is special in your case is that you are using IIS 7.5 which does not allow all verbs by default.

You need to allow the OPTIONS verb

IIS 7.5, Web Service and HTTP 405 error

Community
  • 1
  • 1
Shiraz Bhaiji
  • 60,773
  • 31
  • 133
  • 239
  • Yeah, I found this article already. The .svc handlers already accept all verbs. For the Firefox HTTP Access Control, I added what I believe are the necessary response headers to get things working, as you can see from the response I copy/pasted. – Tedderz Sep 15 '11 at 17:25
  • @Tedderz you added the necessary response headers, but you need to return a 200 response, not a 405. – Boris Zbarsky Sep 15 '11 at 17:35
  • 1
    I actually noticed that I didn't have the [WebInvoke(Method="*")] attribute mentioned in the link. But, when I add it, WCF throws a compilation error. Operation 'xxxx' in contract 'xxxx' specifies Method '*' on the WebGetAttribute/WebInvokeAttribute, but the only allowed values for Method are GET or POST. Other values are not supported by 'System.ServiceModel.Description.WebScriptEnablingBehavior'. Any idea how to work around this? Googling it doesn't seem to bring up much of anything. – Tedderz Sep 15 '11 at 17:49