我正在使用我已用于在我的数据库中发布其他复杂对象的REST客户端。
我无法发布太多代码,因为它与工作相关,但我正在尝试从我的其他客户端发送到Web API:
{"BinID":"PBN0012","BinType":"Wash","IsDeleted":false,"ModifiedDateTime":"2014-07-11T17:51:49.670028+00:00","ModifiedByUID":"00000000-0000-0000-0000-000000000000","BatchBins":[],"BinsInUses":[]}
这是JsonConvert序列化后的对象。
我正在使用HttpWebResponse(并在Xamarin上获取HTTP 500内部服务器错误 - 和System.ArgumentException“路径中的非法字符”。
即使我尝试直接通过SOAP UI发布,也会收到以下消息:
{
"$id": "1",
"Message": "An error has occurred."
}
这是我在浏览器中输入“(IP Address ....)/ Api / Bins / GetBins时所得到的:
[{"$id":"1","BatchBins":[],"BinsInUses":[{"$id":"2","Bin":{"$ref":"1"},"BinID":"PBN0001","EntrySequence":1}],"BinID":"PBN0001","BinType":"Wash","IsDeleted":false,"ModifiedDateTime":"2014-06-02T00:00:00","ModifiedByUID":"b6c1b64f-874b-4180-949a-97c77cc4194c"},{"$id":"3","BatchBins":[],"BinsInUses":[{"$id":"4","Bin":{"$ref":"3"},"BinID":"PBN0002","EntrySequence":2}],"BinID":"PBN0002","BinType":"Wash","IsDeleted":false,"ModifiedDateTime":"2014-06-02T00:00:00","ModifiedByUID":"b6c1b64f-874b-4180-949a-97c77cc4194c"},{"$id":"5","BatchBins":[],"BinsInUses":[{"$id":"6","Bin":{"$ref":"5"},"BinID":"PBN0003","EntrySequence":3}],"BinID":"PBN0003","BinType":"Wash","IsDeleted":false,"ModifiedDateTime":"2014-06-02T00:00:00","ModifiedByUID":"b6c1b64f-874b-4180-949a-97c77cc4194c"},{"$id":"7","BatchBins":[],"BinsInUses":[{"$id":"8","Bin":{"$ref":"7"},"BinID":"PBN0004","EntrySequence":4}],"BinID":"PBN0004","BinType":"Wash","IsDeleted":false,"ModifiedDateTime":"2014-06-02T00:00:00","ModifiedByUID":"b6c1b64f-874b-4180-949a-97c77cc4194c"},{"$id":"9","BatchBins":[],"BinsInUses":[],"BinID":"PBN0005","BinType":"Wash","IsDeleted":false,"ModifiedDateTime":"2014-06-02T00:00:00","ModifiedByUID":"b6c1b64f-874b-4180-949a-97c77cc4194c"},{"$id":"10","BatchBins":[],"BinsInUses":[],"BinID":"PBN0006","BinType":"Dryer","IsDeleted":false,"ModifiedDateTime":"2014-06-02T00:00:00","ModifiedByUID":"b6c1b64f-874b-4180-949a-97c77cc4194c"},{"$id":"11","BatchBins":[],"BinsInUses":[],"BinID":"PBN0007","BinType":"Dryer","IsDeleted":false,"ModifiedDateTime":"2014-06-02T00:00:00","ModifiedByUID":"b6c1b64f-874b-4180-949a-97c77cc4194c"},{"$id":"12","BatchBins":[],"BinsInUses":[],"BinID":"PBN0008","BinType":"Dryer","IsDeleted":false,"ModifiedDateTime":"2014-06-02T00:00:00","ModifiedByUID":"b6c1b64f-874b-4180-949a-97c77cc4194c"},{"$id":"13","BatchBins":[],"BinsInUses":[],"BinID":"PBN0009","BinType":"Dryer","IsDeleted":false,"ModifiedDateTime":"2014-06-02T00:00:00","ModifiedByUID":"b6c1b64f-874b-4180-949a-97c77cc4194c"},{"$id":"14","BatchBins":[],"BinsInUses":[],"BinID":"PBN0010","BinType":"Dryer","IsDeleted":false,"ModifiedDateTime":"2014-06-02T00:00:00","ModifiedByUID":"b6c1b64f-874b-4180-949a-97c77cc4194c"},{"$id":"15","BatchBins":[],"BinsInUses":[],"BinID":"PBN0011","BinType":"Wash","IsDeleted":false,"ModifiedDateTime":"2014-07-03T15:34:11.67","ModifiedByUID":"9f05ab31-2521-4a7e-9258-b7092aae5058"}]
Bin类包括:
public partial class Bin
{
public Bin()
{
this.BatchBins = new HashSet<BatchBin>();
this.BinsInUses = new HashSet<BinsInUse>();
}
public string BinID { get; set; }
public string BinType { get; set; }
public bool IsDeleted { get; set; }
public System.DateTime ModifiedDateTime { get; set; }
public System.Guid ModifiedByUID { get; set; }
public virtual ICollection<BatchBin> BatchBins { get; set; }
public virtual ICollection<BinsInUse> BinsInUses { get; set; }
}
数据库中“Bin”的表格包含以下列:
BinID (PK, nvarchar(100),not null)
BinType (nvarchar(5), not null)
IsDeleted (bit, not null)
ModifiedDateTime (datetime,not null)
ModifiedByUID (uniqueidentifier, not null)
我知道我使用了正确的类型,考虑到我的其他对象通过了很好。关于如何让json字符串发布的任何建议??
答案 0 :(得分:0)
大家都知道,如果他们遇到这种错误并且无法找到解决方案,你可能会遇到同样的问题。
我在我的API中复制和粘贴方法以节省时间(因为许多方法/类具有相似的名称),最后我得到两个具有相同名称的方法;我忘了更改方法名称。仅供将来参考。