导致此错误消息的原因是什么?远程服务器返回错误:(422) Unprocessable Entity [英] What causes this error message? The remote server returned an error: (422) Unprocessable Entity

查看:284
本文介绍了导致此错误消息的原因是什么?远程服务器返回错误:(422) Unprocessable Entity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 WCF 向 REST API 提交请求;这是我所做的:

I try to submit a request to a REST API using WCF; here's what I've done:

namespace Sample
{
    [ServiceContract]
    [XmlSerializerFormat]
    public interface ISampleApi
    {
        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "users.xml", ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml)]
        User CreateUser(User user);
    }
}

这是我的User类:

namespace Sample.Entity
{
    [XmlRoot("user")]
    public class User
    {
        [XmlElement("company")]
        public string Company { get; set; }

        [XmlElement("country-code")]
        public string ContryCode { get; set; }

        [XmlElement("created-at")]
        public DateTime CreatedAt { get; set; }

        [XmlElement("email")]
        public string Email { get; set; }

        [XmlElement("external-identifier")]
        public string ExternalIdentifier { get; set; }

        [XmlElement("id")]
        public int Id { get; set; }

        [XmlElement("measurement-system")]
        public string MeasurmentSystem { get; set; }

        [XmlElement("profile")]
        public string Profile { get; set; }

        [XmlElement("url")]
        public string Url { get; set; }

        [XmlElement("username")]
        public string Username { get; set; }

        [XmlElement("account-type")]
        public string AccountType { get; set; }
    }
}

但是当我调用 CreateUser 方法并将 User 对象传递给它时,我收到此错误消息:

But when I call CreateUser method and pass a User object to it I receive this error message:

远程服务器返回错误:(422) Unprocessable Entity.

知道是什么原因造成的吗?

Any idea what causes this?

推荐答案

该异常意味着 Web 服务器响应错误代码,即 422.您需要与远程站点的管理员核实,为什么会这样.(或者查看响应的正文,如果有返回,它可能包含一些提示).

That exception means that the web server responded with an error code, namely 422. You will need to check with the administrator of the remote site, why that might be. (Or look at the body of the response if any was returned, it might include some hints).

错误代码422的解释如下:http://tools.ietf.org/html/rfc4918#section-11.2

Here is the explanation of error code 422: http://tools.ietf.org/html/rfc4918#section-11.2

您发送到服务器的请求很可能以某种方式无效.如果不知道您针对哪个系统发送了哪个请求,就不可能知道确切的错误是什么.

The request you are sending to the server is most likely invalid in some way or another. What the exact error might be, is impossible to tell without knowing which request you are sending against which system.

这篇关于导致此错误消息的原因是什么?远程服务器返回错误:(422) Unprocessable Entity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆