我有方法WCF像如何接受JSON字符串作爲參數
空隙最終化(串jsonstring);
我用一樣的finalize/{JSON}請求URL
但如果itried與JSON稱之爲它會給像charachters的壞請求原因:等
如何解決
這是我使用的方法
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
UriTemplate = "FinalBooking/{BookingJsonString}")]
public int Finalize(string JsonString)
{
int result; // 1 success , 0 faill
JavaScriptSerializer json_serializer = new JavaScriptSerializer();
Routess routes =
(Routess)json_serializer.DeserializeObject(JsonString);
using (XEntities context = new XEntities())
{
result = context.usp_Final(routes.TypeID, routes.regID, routes.CycleID, routes.DateTime,
routes.LocationID, routes.PatID, routes.PO, routes.BTID, routes.DID);
}
return result;
}
}
和示例中的數據的代碼簡單JSON字符串等
{"DateTime":"03/09/2012 09:00","CycleID":6,"BTID":31,"DiseaseID":814,"LocID":36,"PatID":13,"PO":1,"TypeID":744,"rID":-1}
問候
你確定':'是原因嗎? ':'在請求中是合法的。你可以發佈一些代碼嗎?和你正在傳遞的json字符串? – DarthVader
你還使用什麼綁定? http? – DarthVader
如果你在你的方法中設置了斷點,它會進入嗎?它是否將JSON字符串傳遞到您的方法中,並且Json序列化器會拋出錯誤,還是WCF拋出錯誤? – CodingWithSpike