Been beating about this problem for a while now.
Under IIS6 and windows authentication, whenever I attempt to use jquery to post to a WCF service, the service method is called and executed but all of the post data (the method arguments) are null. This only seems to occur on the IE8 version that is on that machine. This does not occur in Firefox and this also does not occur, strangely enough, when fiddler is running (acting as a proxy).
This code works fine under IIS7 and appears to work fine under IIS6 Anonymous Authentication.
The post data is just JSON.
$.callService('GetCurrentTemplates', pagingData, GetCurrentTemplateSucceeded, ServiceFailed);
$.callService = function (url, data, successHandler, failHandler) {
var applicationUrl = $("#hdApplicationUrl").val();
$.ajax({
type: "POST", //GET or POST or PUT or DELETE verb
url: applicationUrl + "Service.svc/" + url, // Location of the service
data: $.jsonSerialize(data), //Data sent to server
contentType: "application/json; charset=utf-8", // content type sent to server
dataType: "json", //Expected data format from server
processdata: true, //True or False
success: function (result) {
if (result == null) {
var resultObj = new Object();
resultObj.status = 401;
resultObj.statusText = 'Unauthorized';
$.showError(resultObj);
return;
}
if (successHandler != null && successHandler != undefined)
successHandler(result);
}, // When success
error: function (result) {
$.showError(result);
} // When Service call fails
});
The WCF service was designed to use the WebServiceHostFactory and web.config definitions are as follows:
<services>
<service name="Company.Core.TemplateService" behaviorConfiguration="templateWcfBehavior">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="templateWebHttpBinding" behaviorConfiguration="jsonEndpointBehavior" contract="Company.Core.ITemplateService" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="jsonEndpointBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="templateWcfBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<webHttpBinding>
<binding name="templateWebHttpBinding" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</webHttpBinding>
The service file is, of course, under Anonymous Access (not windows authentication).
If we run -everything- under anonymous access, the jquery passes the service the appropriate data, the methods return what we want them to, etc. The same occurs if we run under integrated mode authentication but have fiddler up on the client.
It seems that Fiddler is mutating the packets to fix an obvious defect - having trouble as the issue only seems to occur local to a machine (precluding the use of wireshark/ethereal to sniff packets and determine the exact differences).
At this point, any advice / information you can offer would be extremely helpful.
Update 2011-09-07: Interesting enough, if I contact the service (and asp.net spins it up) - I can then change the service from Anonymous Access to Windows Integrated Authentication. While the service is already spun up and activated, this actually causes everything to run perfectly. If I wait for IIS6 to flush the metabase changes to disk and run IISreset (or recycle the app pool), it fails. The reason it fails is due to "Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service. ". Looks like I am in a quandary. For whatever reason, under anonymous access my argument post settings are lost. If the service is already spun up, I can change the file to Integrated mode auth and everything will work. If the service is not spun up (or is lost as the app pool recycles) and it is set to integrated mode authenticatin, I fail with the error noted above. Ye Gads!
Cause appears to be once IE encounters NTLM, it then requires NTLM for all other pages on the site. See http://support.microsoft.com/?id=251404 “You cannot post data to a non-NTLM-authenticated Web site”
Suggested workaround is if you enable NTLM on anything, enable NTLM on everything.
Alternative workaround is a client side registry hacks that change the NTLM auth process. From that link:
Presumably Fiddler makes it work because it is doing the NTLM handshake differently.