C# 使用Fiddler发布到ASP.NET Web API时出现错误500

C# 使用Fiddler发布到ASP.NET Web API时出现错误500,c#,asp.net,json,asp.net-web-api,C#,Asp.net,Json,Asp.net Web Api,我正在尝试学习如何使用Visual Studio 2012创建自己的Web API。我目前通过下面的模型设置了两个数据库表 国家表很好,很简单。我可以用Fiddler成功发布新条目。然而,当我试图发布到球员表时,我得到了500个错误。当然,我不知道我错在哪里 Player.cs public class Player { public Guid PlayerId { get; set; } [Required] public string Username { get;

我正在尝试学习如何使用Visual Studio 2012创建自己的Web API。我目前通过下面的模型设置了两个数据库表

国家表很好,很简单。我可以用Fiddler成功发布新条目。然而,当我试图发布到球员表时,我得到了500个错误。当然,我不知道我错在哪里

Player.cs

public class Player
{
    public Guid PlayerId { get; set; }
    [Required]
    public string Username { get; set; }
    [Required]
    public string Address { get; set; }
    public string Address2 { get; set; }
    [Required]
    public string Town { get; set; }
    [Required]
    public string State { get; set; }
    [Required]
    public string Postcode { get; set; }
    [Required]
    public int CountryId { get; set; }
    [Required]
    public string Email { get; set; }
    public string Telephone { get; set; }
    public string Mobile { get; set; }
    public DateTime? DateJoined { get; set; }

    // Navigation properties
    public Country Country { get; set; }
}
    public class Country
{
    public int CountryId { get; set; }
    public string Name { get; set; }
}
Countries.cs

public class Player
{
    public Guid PlayerId { get; set; }
    [Required]
    public string Username { get; set; }
    [Required]
    public string Address { get; set; }
    public string Address2 { get; set; }
    [Required]
    public string Town { get; set; }
    [Required]
    public string State { get; set; }
    [Required]
    public string Postcode { get; set; }
    [Required]
    public int CountryId { get; set; }
    [Required]
    public string Email { get; set; }
    public string Telephone { get; set; }
    public string Mobile { get; set; }
    public DateTime? DateJoined { get; set; }

    // Navigation properties
    public Country Country { get; set; }
}
    public class Country
{
    public int CountryId { get; set; }
    public string Name { get; set; }
}
我在Fiddler请求头中设置了以下内容类型:

内容类型:application/json;字符集=utf-8

我试图发布到播放器表的数据如下:

{“PlayerId”:“hfjdfk”,“Username”:“TickledPink”,“Address”:“我的地址”,“Address 2”:“镇”:“Llanerchymedd”,“State”:“Anglesey”,“Postcode”:“LL71”,“Email”:myemail@me.net“,”电话“:”1234567“,”手机“:”456789“,”日期加入“,”国家ID“:”1“}”


我对Web API知之甚少甚至一无所知,但“hfjdfk”是有效的GUID吗?

Hmmm。。。好问题。我假设它将接受任何字符串作为GUID。我来看看,我刚试过。它可能不是有效的GUID。我已经用应该是有效字符串的字符串替换了它,但仍然是相同的问题。您能进入web api代码吗?这就是我经常解决或追踪问题的方式。500美元对你来说没什么用,我试过了。我的PlayerController类中的断点没有被触发,这表明它甚至没有执行代码。在这种情况下,我可能会怀疑Fiddler有问题,事实上我在Windows 8上运行它,但我可以发布到Countries表上,很好。。。如果我知道WebAPI脚手架中类的执行顺序,那么我可能能够确定问题并从那里开始工作。你能在没有Fiddler的情况下成功地发布到播放器表吗?