ASP.Net Web API似乎找不到正确的方法

时间:2015-06-17 18:19:24

标签: c# asp.net asp.net-web-api

我正在创建一个新对象,并尝试将其POST到我的Web API服务以保存到数据库。

我通过这种方式传递:

private RestClient<Profile> profileClient = new RestClient<Profile>(System.Configuration.ConfigurationManager.AppSettings["WebApiUrl"],
        "xxxxxxxxxxxxxx", true);
///...
var postResult = profileClient.PostRequest("api/Profile", newProfile).Result;

我试图得到的服务的ProfileController方法是:

[SecretAuthenticationFilter(SharedSecretName = "xxxxxxxxxxxxxx", HmacSecret = true)]      
public class ProfileController : ApiController
{

    //....

    [HttpGet]
    public IList<Profile> GetProfile()//IHttpActionResult GetProfile()//
    {
        var returnContent = _profileservices.GetAll();//Ok(_profileservices.GetAll());//
        return returnContent;
    }

    [ResponseType(typeof(Profile))]
    public IHttpActionResult GetProfile(Guid id)
    {
        Profile Profile = _profileservices.Get(id);
        if (Profile == null)
        {
            return NotFound();
        }

        return Ok(Profile);
    }

    [HttpPost]
    [ResponseType(typeof(Profile))]
    public IHttpActionResult PostProfile(Profile Profile)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }
        GuidValue = Guid.NewGuid(); //CreateGuid();

        Resource res = new Resource();
        res.ResourceId = GuidValue;
        var data23 = Resourceservices.Insert(res);

        Profile.ProfileId = data23.ResourceId;
        _profileservices.Insert(Profile);

        return CreatedAtRoute("DefaultApi", new { id = Profile.ProfileId }, Profile);
    }
}

路由是:

            config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
        config.Routes.MapHttpRoute(
            name: "API Default",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: new { id = RouteParameter.Optional });
        config.Formatters.XmlFormatter.UseXmlSerializer = true;

我的留言是:

  

{“消息”:“验证对服务的请求时出错:配置文件:PostProfile”}

GET调用Web服务工作。

0 个答案:

没有答案