zoukankan      html  css  js  c++  java
  • wcf接口输出为json格式

    接口定义:

    [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;
    }

  • 相关阅读:
    图片剪切
    js事件(Event)知识整理
    原生JavaScript事件详解
    underscore源码解析
    win7 vi工具
    开源java数据库库
    win7快捷键
    win7 绿色版MySQL安装与配置
    maven jetty
    javax inect
  • 原文地址:https://www.cnblogs.com/yyq745201/p/5723638.html
Copyright © 2011-2022 走看看