WCF rest服务500内部服务器错误

本文关键字:服务器 错误 内部 rest 服务 WCF | 更新日期: 2023-09-27 17:57:35

访问服务方法时遇到followed异常。所有的GET方法在我的服务上都能正常工作,但当我按照下面的方式运行POST方法时,我会得到500内部服务器错误。

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

{"userId":"30155496","locationId"::"10","order":"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);

错误消息

传入消息具有意外的消息格式"Raw"。这个操作的预期消息格式为"Xml"Json’。这个可以是因为尚未在上配置WebContentTypeMapper结合有关更多信息,请参阅WebContentTypeMapper的文档详细信息。

WCF rest服务500内部服务器错误

以这种方式更改您的合同:

[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类在哪里:

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

现在,试着跑吧。确保JSON的格式正确。