接口定义:
[OperationContract]
[WebInvoke(UriTemplate = "AddTask?taskId={taskId}&processGuid={processGuid}", Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
Stream AddTask(Stream request, string taskId, string processGuid);
处理完任务,输出流返回的时候加上System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.ContentType = "application/json";就行了
/// <summary>
/// 辅助方法,用于输出流
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
private Stream GetJsonStream(string str)
{
MemoryStream ms = new MemoryStream();
StreamWriter sw = new StreamWriter(ms);
sw.AutoFlush = true;
sw.Write(str);
ms.Position = 0;
System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.ContentType = "application/json";
return ms;
}