Note that there are some explanatory texts on larger screens.

plurals
  1. POMemoryStream data corruption issue
    primarykey
    data
    text
    <p>I have created a simple REST based WCF service which runs on BasicHttpBinding. In one of my webmethod, I am returning a Stream which points to a JSON response. </p> <p>The Method looks like : </p> <pre><code>[OperationContract] [FaultContract(typeof(ApplicationFault))] [WebInvoke(Method = "POST", UriTemplate = "GetActiveCalls/{nurseid}")] Stream GetActiveCalls(string nurseid); </code></pre> <p>From the body of the GetActiveCalls, I am creating an object of MemoryStream and returning the same as response. The code looks like </p> <pre><code>// Serialize the results as JSON string jsonResult = new JavaScriptSerializer().Serialize(baseResponses); // ContentType json WebOperationContext.Current.OutgoingResponse.ContentType = "application/json"; WebOperationContext.Current.OutgoingResponse.Headers.Add("Cache-Control", "no-cache"); var bytes = Encoding.UTF8.GetBytes(jsonResult); //Parse to memorystream var ms = new MemoryStream(bytes); ms.Seek(0, SeekOrigin.Begin); ms.SetLength(bytes.LongLength); return ms; </code></pre> <p>When trying this from client, I get result like</p> <pre><code>{"LastEvents":[{"FormatValues":"Klic 2 3 4","Icon":null,"Color":"Red","Acknowledged":false,"EventID":28566}],"Message":"","Status":true} </code></pre> <p>But sometimes after invoking the same method for multiple times, I start getting the response as : </p> <pre><code>{"LastEvents":[{"FormatValues":"Klic 2 3 4","Icon":null,"Color":"Red","Acknowledged":false,"EventID":28566}],"Message":"","Statu{"LastEv </code></pre> <p>You can see after "Statu on the JSON response, the stream gets reset and starts getting data from the beginning. </p> <p>It looks strange to me. Can someone point to if I am missing something. </p> <p>*From server side, when I put breakpoint, it seems the MemoryStream has correct response.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload