我有一個WP7遊戲,使用RESTsharp與我的MVC4 RESTful服務器進行通信,但我經常遇到問題,使請求工作,因此我想調試它失敗的地方。如何最好地調試MVC 4 API路線?
這是一個例子,我的GameController
上的構造函數被擊中,但Post
方法沒有命中,我不明白爲什麼。
客戶端代碼:
public void JoinRandomGame()
{
client = new RestClient
{
CookieContainer = new CookieContainer(),
BaseUrl = "http://localhost:21688/api/",
};
client.Authenticator = GetAuth();
RestRequest request = new RestRequest(Method.POST)
{
RequestFormat = DataFormat.Json,
Resource = "game/"
};
client.PostAsync(request, (response, ds) =>
{});
}
Server代碼:
public void Post(int id)
{
if (ControllerContext.Request.Headers.Authorization == null)
{
//No auth
}
if (!loginManager.VerifyLogin(ControllerContext.Request.Headers.Authorization.Parameter))
{
//Failed login
}
string username;
string password;
LoginManager.DecodeBase64(ControllerContext.Request.Headers.Authorization.Parameter, out username, out password);
gameManager.JoinRandomGame(username);
}
我的路線是這樣的
routes.MapHttpRoute(
name: "gameAPI",
routeTemplate: "api/game/{gameId}",
defaults: new
{
controller = "game",
gameId = RouteParameter.Optional
}
);
http://haacked.com/archive/2008/03/13/url-routing-debugger。aspx – 2012-07-13 15:01:53
當我通過WP7模擬器訪問我的RESTful服務時,無法看到調試器信息? – Mech0z 2012-07-13 15:27:22