I’m trying to perform a POST to a WCF service.
When using Firefox 8, the browser first sends a OPTIONS HTTP request.
This works fine when I use WebMessageBodyStyle.Bare as the BodyStyle, but what I want is to use the Wrapped body style.
When I switch to Wrapped, the OPTIONS request is refused with 400 status.
I suspect that this is due to the fact that the OPTIONS request has no body hence the BodyStyle parser fails.
Here’s the layout of my web mehod:
[OperationContract(ProtectionLevel = ProtectionLevel.None)]
[WebInvoke(Method = "*",
BodyStyle = WebMessageBodyStyle.Wrapped,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
bool Ping(String msg);
And I use the following jquery for invoking:
$.ajax({
url: "http://localhost/Server/Service.svc/Ping",
data: JSON.stringify({msg: msg}),
type: "POST",
processData: false,
contentType: "application/json",
timeout: 10000,
dataType: "text"
});
I would appreciate any help on this issue…
Thanks!!
I solved this by adding a custom IErrorHandler to the Enpoint Behavior.
General instructions for how to do this are here.
and