C#-积累-Response写入返回值-Transfer-Encoding chunked-中断请求
private void ReplyAndAbortRequest<T>(T t, IClientChannel channel, InstanceContext instanceContext) //
{
String res = JsonHelper.ObjectToJsonNotForSerialize(t);
HttpContext.Current.Response.AddHeader("Content-Type", "application/json");//实测两个都可以
HttpContext.Current.Response.ContentType = "application/json";//实测两个都可以
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Length","");//去掉Transfer-Encoding:chunked 头必须 但是某些情况导致请求不能中断
HttpContext.Current.Response.Write(JsonHelper.ObjectToJsonNotForSerialize(t));
HttpContext.Current.Response.Flush();
// HttpContext.Current.Response.End(); //20180730 实测发布iis服务中时这个导致不能终止,第二次无法请求,甚至无法发布成功
HttpContext.Current.Response.Close();//这里处理结束后不要在BeforeSendReply()中继续调用
instanceContext.Abort();//起关键作用 中断
channel.Abort();
channel.Close();
HttpContext.Current.Request.Abort();
}