2014-04-09 158 views
-1

我在訪問服務方法時遇到了緊隨的異常。所有GET方法在我的服務上正常工作,但是當我運行POST方法時,後續出現500內部服務器錯誤。WCF休息服務500內部服務器錯誤

https://mservice.domain.com/ServicesRestful.svc/json/addorder

{ 「用戶id」: 「30155496」, 「locationId」: 「10」, 「訂單」: 「LOREM」}

服務代碼

[OperationContract] 
[WebInvoke(Method = "POST", UriTemplate = "addorder", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)] 
[FaultContract(typeof(ServiceException), Name = "ServiceException")] 
Standard AddOrder(string personId, int locationId, string order); 

錯誤消息

傳入消息具有意外的消息格式「原始」。預期的操作消息格式是'Xml'; 'Json的'。這可以是 ,因爲尚未在 綁定上配置WebContentTypeMapper。有關更多 的詳細信息,請參閱WebContentTypeMapper的文檔。

+1

因此,在錯誤信息是純英文後,*您是否*請參閱WebContentTypeMapper的文檔以獲取更多詳細信息。 – nvoigt

回答

0

您的合同變更這樣:

[OperationContract] 
[WebInvoke(Method = "POST", UriTemplate = "addorder", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)] 
[FaultContract(typeof(ServiceException), Name = "ServiceException")] 
Standard AddOrder(Order order); 

如果您Order類是:

[DataMember] 
public class Order 
{ 
    [DataContract] 
    public string personId {get; set;} 
    [DataContract] 
    public int locationId {get; set;} 
    [DataContract] 
    public string order {get; set;} 
} 

現在,嘗試和運行。確保您的JSON格式正確。