REST服务上的错误请求错误使用POST(json数据)调用方法?

嗨,我是RESTful WCF的新手,我正在尝试使用POST对webservice方法进行简单的调用,这是我的代码

Service Interface code [ServiceContract] public interface IJsonSave { [OperationContract] [WebInvoke(UriTemplate = "/SaveJason", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)] string SaveJason(string value); } 

web.config文件代码

                                   

我尝试使用提琴手她是我的标题

 POST http://localhost:50267/JsonSave.svc/Rest/SaveJason User-Agent: Fiddler Content-Type: application/json Data-Type: json Host: localhost:50267 

申请机构:

  ({"value":"asdfasd"}) 

它给出了HTTP/1.1 400 Bad Request错误,当启用调试细节时,它会给出以下堆栈跟踪

 The server encountered an error processing the request. The exception message is 'Error in deserializing body of request message for operation 'SaveJason'. The OperationFormatter could not deserialize any information from the Message because the Message is empty (IsEmpty = true).'. See server logs for more details. The exception stack trace is: at System.ServiceModel.Dispatcher.PrimitiveOperationFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.CompositeDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet) 

我google了很多,并尝试了所有可用的解决方案,但它仍然没有工作任何帮助将是伟大的。它适用于SOAP只是给REST错误!

为了收集有关数据流和错误位置的其他信息,您可以从服务端启用WCF跟踪中受益。 以下链接应提供足够的详细信息: http : //msdn.microsoft.com/en-us/library/ms733025(v = vs.110).aspx

关于您的方案中的错误,我怀疑没有为客户端和服务一致地设置消息编码。 我想知道是否可能:

 BodyStyle = WebMessageBodyStyle.WrappedRequest 

应该是:

 BodyStyle = WebMessageBodyStyle.Wrapped 

要么

 BodyStyle = WebMessageBodyStyle.Bare 

所以请求和响应具有相同的包装样式。

问候,