///////
There are a few
alternatives. The simplest one is to have your method return a HttpResponseMessage
, and create that response
with a StringContent
based on your string
Normal Code >>
DataTable dt = new DataTable();
return Request.CreateResponse(HttpStatusCode.OK, item);
return Request.CreateResponse(HttpStatusCode.NotFound);
public HttpResponseMessage Get() {
string yourJson = GetJsonFromSomewhere();
var response = this.Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent(yourJson,
Encoding.UTF8, "application/json");
return response;
}
Method >2.
public HttpResponseMessage Get() {
string yourJson = GetJsonFromSomewhere();
if (!string.IsNullOrEmpty(yourJson)) {
var response = this.Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent(yourJson,
Encoding.UTF8, "application/json");
return response;
}
throw new
HttpResponseException(HttpStatusCode.NotFound);
}
No comments:
Post a Comment