简体   繁体   English

WCF 休息服务 500 内部服务器错误

[英]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.

相关问题 从 http 访问 WCF 服务时出现 500 内部服务器错误并且由于相同原因无法添加服务引用 - 500 Internal Server error while accessing WCF service from http and unable to add service reference for the same reason 从http和Google Chrome扩展程序简单REST客户端访问WCF服务时出现500间隔服务器错误 - 500 Interval Server Error while accessing WCF service from http and Google Chrome Extension Simple REST Client WCF服务引发内部服务器错误 - WCF Service Throws Internal Server Error Web Api和WCF中的HTTP发布内部服务器错误500 - Http Post Internal Server Error 500 in Web Api & WCF 远程服务器返回错误:(500)内部服务器错误Web服务 - The remote server returned an error: (500) Internal Server Error Web service HttpClient.SendAsync:500 - Windows服务应用程序中的内部服务器错误 - HttpClient.SendAsync: 500 - Internal Server Error in Windows Service Application Web部署代理服务返回500内部服务器错误 - Web Deployment Agent Service returns a 500 Internal Server Error 500-内部服务器错误,Windows Azure云服务 - 500 - Internal Server Error, Windows Azure Cloud Service Web服务响应返回500内部服务器错误 - Web Service Response returns a 500 Internal Server Error 获取内部服务器错误500 - Getting Internal Server Error 500
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM