[英]WCF rest service 500 internal server error
I encountered followed exception while accessing service method.All GET methods working properly on my service but when i run a POST method as followed i am getting 500 Internal Server Error.我在访问服务方法时遇到了以下异常。所有 GET 方法在我的服务上正常工作,但是当我按照以下方式运行 POST 方法时,我收到 500 内部服务器错误。
https://mservice.domain.com/ServicesRestful.svc/json/addorder https://mservice.domain.com/ServicesRestful.svc/json/addorder
{"userId":"30155496","locationId":"10","order":"lorem"}
{"userId":"30155496","locationId":"10","order":"lorem"}
Service Code服务代码
[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);
Error message错误信息
The incoming message has an unexpected message format 'Raw'.
传入的消息具有意外的消息格式“原始”。 The expected message formats for the operation are 'Xml';
操作的预期消息格式是“Xml”; 'Json'.
'杰森'。 This can be because a WebContentTypeMapper has not been configured on the binding.
这可能是因为尚未在绑定上配置 WebContentTypeMapper。 See the documentation of WebContentTypeMapper for more details.
有关更多详细信息,请参阅 WebContentTypeMapper 的文档。
Change your contract in this way:以这种方式更改您的合同:
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "addorder", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
[FaultContract(typeof(ServiceException), Name = "ServiceException")]
Standard AddOrder(Order order);
Where your Order
class is:您的
Order
类在哪里:
[DataContract]
public class Order
{
[DataMember]
public string personId {get; set;}
[DataMember]
public int locationId {get; set;}
[DataMember]
public string order {get; set;}
}
Now, try and run.现在,尝试运行。 Make sure that your
JSON
is in proper format.确保您的
JSON
格式正确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.