Streaming WCF DataService Response
I'm trying to stream the response of my wcf dataservice to make waiting time more user friendly. The response is in XML format (I use entity framework 4.1) I have these predefined events
service.SendingRequest += service_SendingRequest;
service.ReadingEntity += service_ReadingEntity;
service.WritingEntity += service_WritingEntity;
a开发者_如何学Gofter that I call DataServiceQuery Execute method
var items = myItems.Query.Execute();
Here is the body of SendingRequest event
var response = (HttpWebResponse)e.Request.GetResponse();
var resStream = response.GetResponseStream();
var sb = new StringBuilder();
var buf = new byte[1024];
string tempString;
int count;
do
{
count = resStream.Read(buf, 0, buf.Length);
if (count != 0)
{
tempString = Encoding.ASCII.GetString(buf, 0, count);
sb.Append(tempString);
}
}
while (count > 0);
So the problem is that after that nothing is happening. The next event ReadingEntity is not firing. How can I solve this issue?
You cannot change the way how service sends the request. The event is there to allow you modify you request headers but the service must call it itself. Your code has most probably broke the service's functionality. Also I don't think that what you are trying to do is possible. WCF Data Service still uses WCF internally and unless it is using streaming it will always wait for the whole message before it passes it to your upper layer (context). Streaming in WCF data services is possible only when implementing streaming provider and it is mostly for downloading binary data not for downloading common data in chunks.
What you are trying to do would require chunked response (used in WCF streaming). With default WCF feature set working with chunked response is out of your control.
精彩评论