所以我修改了todo服務,它給了我一個響應。ServiceStack返回XML格式的輸入響應
當我故意拋出一個未處理的錯誤來測試ServiceExceptionHandler代碼如果我使用默認的/Backbone.Todos/todo/1?format=json
,那很好。
但是,如果使用/Backbone.Todos/todo/1?format=xml
,它說:
XML Parsing Error: not well-formed Location: /Backbone.Todos/todo/1 Line Number 1, Column 2:
這裏是我的代碼:
public class AppHost : AppHostBase {
public override void Configure(Funq.Container container) {
//Unhandled errors
this.ServiceExceptionHandler = (req, ex) => {
var res = new { //i return a dynamic object here ... and it doesn't work
Result = null as object,
ResponseStatus = new ResponseStatus() {
ErrorCode = "Error",
Message = "Not available",
StackTrace = "Not available"
}
};
return res;
};
//...
}
//....
}
//My normal request/response dtos look like this:
//-----------------------------------------
[Route("/todo/{id}", "GET")] //display req
public class GetTodo : IReturn<TodoResponse> {
public long Id { get; set; }
}
public class TodoResponse : IHasResponseStatus {
public IList<Todo> Result { get; set; }
public ResponseStatus ResponseStatus { get; set; }
}
的事情是,當錯誤發生我不能構建一個正確的響應類型不知道它是什麼類型。我只接收請求和異常作爲參數,但不是響應類型。
也就是說,我想在這裏構造一個正確類型的響應對象。 – Tom