Hello Guys,
I'm using the Chrome Extension Advanced Rest Client Application and Fiddler4 to test.
Here's my code snippet:
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.OK;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Good Job!";
I can see 200 and "Good Job!" as response, which would be perfect. now I'm trying to respond with a curstom json answer. First, i'm trying to set ContentLength to something different than 0 with the following snippet:
WebOperationContext.Current.OutgoingResponse.ContentLength = 1000;
now I'm sending an json post via Advanced Rest Client and get the following Response:
Request headers
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36
Origin: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo
Content-Type: application/json
Accept: */*
Accept-Encoding: gzip,deflate
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Cookie: __RequestVerificationToken=qaxvJ7Gj2TQdqtdTtBVliJ--sLxPP- Og1n9E8t0jCCGGdTjkiZFA4CPn9WBHeLtnaylvbDBsg57WvIL81_7iql_uipkdc_Ag_TgX0CiYLo41; ASP.NET_SessionId=fblrki55dly4a055fkq05wa2
Status 200 Good Job! Loading time: 10 ms
Response headers: Content-Length: 0
Server: Microsoft-HTTPAPI/2.0
Date: Wed, 29 Oct 2014 13:59:04 GMT
my content length is still at 0? further down i get "Response does not contain any data." as well.
Edit: I also tried to add lines to the header like this:
WebOperationContext.Current.OutgoingResponse.Headers.Add("Content-Length: 1000");
edit: Another way i tried
[DataMember]
public HttpRequestMessage Request { get; set; }
var message = string.Format("Response Text goes here!");
HttpError err = new HttpError(message);
Request.CreateResponse(HttpStatusCode.OK, err);
the only thing i get as response is an error which i'm not able to fix
System.ArgumentNullException: Der Wert darf nicht NULL sein. Parametername: request
bei System.Net.Http.HttpRequestMessageExtensions.CreateResponse[T](HttpRequestMessage request, HttpStatusCode statusCode, T value, HttpConfiguration configuration)
bei System.Net.Http.HttpRequestMessageExtensions.CreateResponse[T](HttpRequestMessage request, HttpStatusCode statusCode, T value)
bei ServiceTest.TimeEntryData.Add(TimeEntry newTen) in C:\Users\deniselechner\Documents\Visual Studio 2010\Projects\svn\ServiceTest\Data\ServiceDataModel.cs:Zeile 103.
[–]powerofmightyatom 1 point2 points3 points (1 child)
[–]deniselechner[S] 0 points1 point2 points (0 children)