wcf服务返回json
private static void CreateErrorReply(OperationContext operationContext, string key, HttpStatusCode statusCode, ResponseBase info=null, string description = null)
{
using (Message reply = Message.CreateMessage(MessageVersion.None, "", info, new DataContractJsonSerializer(typeof(ResponseBase))))
{
var wbfProp = new System.ServiceModel.Channels.WebBodyFormatMessageProperty(WebContentFormat.Json);
// 构造HTTP响应消息
HttpResponseMessageProperty responseProp = new HttpResponseMessageProperty()
{
StatusCode = statusCode,
StatusDescription = description ?? "",
SuppressEntityBody=false,
};
reply.Properties.Add(HttpResponseMessageProperty.Name, responseProp);
reply.Properties.Add(WebBodyFormatMessageProperty.Name, wbfProp);
operationContext.RequestContext.Reply(reply);
// 因为配置使用transferMode="StreamedRequest",如果请求不关闭,还会进入这个类,导致这个方法被执行两次,不能返回正常的错取码
operationContext.RequestContext.Close();
operationContext.RequestContext = null;
}
}
wcf服务返回json的更多相关文章
- 【.net 深呼吸】聊聊WCF服务返回XML或JSON格式数据
有时候,为了让数据可以“跨国经营”,尤其是HTTP Web有关的东东,会将数据内容以 XML 或 JSON 的格式返回,这样一来,不管客户端平台是四大文明古国,还是处于蒙昧时代的原始部落,都可以使用这 ...
- Android访问WCF服务(使用json实现参数传递)
经过多日努力, 终于勉强弄明白了Android访问WCF服务的方法. 服务端实现 一, 实现服务. 操作契约 [ServiceContract] public interface IService { ...
- jQuery调用WCF服务传递JSON对象
下面这个示例使用了WCF去创建一个服务端口从而能够被ASP.Net页面通过jQuery的AJAX方法访问,我们将在客户端使用Ajax技术来 与WCF服务进行通信.这里我们仅使用jQuery去连接Web ...
- Spring MVC Rest服务 返回json报406错误的解决办法
@ResponseBody & @RequestBody @RequestBody 将 HTTP 请求正文插入方法中,使用适合的HttpMessageConverter将请求体写入某个对象. ...
- WCF服务返回XML或JSON格式数据
第一种方式public string GetData( string format) { string res = null; Student stu = new Student { StuID = ...
- ajax请求web服务返回json格式
由于.net frameword3.5以上添加了对contenttype的检查,当ajax发送请求时,如果设置了contenttype为json,那么请求webservice时,会自动将返回的内容转为 ...
- Downloader调用WCF服务返回文件
Generator using System; using System.Collections.Generic; using System.IO; namespace Downloader { pu ...
- jersey构建rest服务返回json数据
1. eclipse 创建 dynamic web project 2. 将jersey相关jar包放到libs目录下 3. web.xml 增加 jersey 相关内容 <?xml ver ...
- WCF返回JSON的详细配置
开发环境:VS2008,c# 1.新建个WCF服务网站 文件-新建-网站-WCF服务 2,运行一下,提示配置WEB.CONFIG,点击确认. 3,打开web.config增加如下节点: <ser ...
随机推荐
- JS 清除字符串数组中,重复元素
<script language="JavaScript"> <!-- var arrData=new Array(); for(var i=0; i<10 ...
- SQL 游标使用实例
IF EXISTS(SELECT *FROM sysobjects WHERE name='sp_ContestSubmit') DROP PROC sp_ContestSubmit GO -- == ...
- HTTP 错误 500.21 - Internal Server Error 处理程序“ExtensionlessUrlHandler-Integrated-4.0”在其模块列表中有一个错误模块“ManagedPipelineHandler”
导致这个错误出现的原因是因为.net Framework4.0没有注册 解决方法:打开运行命令行,运行下面的命令: C:\WINDOWS\Microsoft.NET\Framework\v4.0.30 ...
- 【News】SpagoBI中国官方微信对外发布
爱数据,爱分析,爱达比 致力于国际优秀开源BI应用在中国的普及推广,用数据开启中小企业智慧之门: 扫描上图二维码,关注SpagoBI中国官方微信,2015年8月18日将在腾讯课堂.百度传课.网易云课堂 ...
- 【html】button按钮的一些问题
问题: button 按钮在不设置 type 属性时,在不同的浏览器作用不一样.举个例子: html: <!doctype html> <html lang="en&quo ...
- canvas应用-思维导图
canvas应用例子-思维导图 效果图如下: 函数说明: // 求圆上一点坐标,返回坐标点 function circlePoint(x, y, r, a) { var tmpx = x + r * ...
- Python: 测试函数是否被调用
# helper class defined elsewhere class CallLogger(object): def __init__(self, meth): self.meth = met ...
- 用Zim替代org-mode?
三年前我玩过Zim,当时还写了一篇<Zim - 普通人的Org-mode>,当时还说我还是会坚持使用emacs org-mode.但最近我又在考虑是不是回头用Zim来写博客文章.整理知识库 ...
- iOS开发问题之Could not instantiate class named NSLayoutConstraint
这个问题在ios6.0之前的版本中运行会出现,因为使用Xcode 4.5之后的版本新建项目默认是选中AutoLayout的,但这个特性是在iOS6.0之后的版本中才支持的. 解决办法是选中.stroy ...
- 命令行下使用javah命令生成.h文件,出现“错误: 无法访问android.app.Activity 找不到android.app.Activity的类文件”的解决方法
在学习NDK中,当我在项目的bin/classes目录下使用javah命令生成头文件时,出现了“错误: 无法访问android.app.Activity 找不到android.app.Activity ...