我想寫一個WCF服務來響應Ajax請求,但是當它試圖反序列化時,我收到了一個奇怪的錯誤。WCF無法反序列化JSON請求
這裏是jQuery的:
$.ajax({
type: 'POST',
url: 'http://localhost:4385/Service.svc/MyMethod',
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({folder:"test", name:"test"})
});
這裏的WCF服務定義:
[OperationContract]
[WebInvoke(UriTemplate = "/MyMethod",
Method = "*", //Need to accept POST and OPTIONS
BodyStyle = WebMessageBodyStyle.WrappedRequest,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
string[] MyMethod(string folder, string name);
我得到了SerializationException
說:「因爲郵件是空的OperationFormatter無法序列化從郵件的所有信息(IsEmpty = true)「。
它發生在方法上System.ServiceModel.Dispatcher.PrimitiveOperationFormatter.DeserializeRequest
指令00000108 mov dword ptr [ebp-18h],0
我不知道我做錯了什麼,但它拒絕爲我工作。一整天都在戰鬥。有任何想法嗎?