c# – 从WCF返回多个响应

栏目: ASP.NET · 发布时间: 6年前

内容简介:翻译自:https://stackoverflow.com/questions/3719594/return-multiple-response-from-wcf

我在服务中有一个WCF服务和一个名为GetStudentList()的方法.当它返回单个响应时工作正常.这样的东西

[WebGet(ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
List<Student> GetStudentList();

但我想返回多个响应,即xml和json都是这样的

[WebGet(ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
[WebGet(ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
List<Student> GetStudentList();

有可能吗?如果是,那怎么样?

它可以在.NET 4.0中使用,但不是以您指定的方式. .NET 4.0为WebHttp行为添加了新参数:

<endpointBehaviors>
    <behavior name="WebHttp">
      <webHttp automaticFormatSelectionEnabled="true" />
    </behavior>
  </endpointBehaviors>

使用自动格式选择时,响应的格式基于:

>从请求中接受标头

>请求的内容类型

>操作时指定的默认格式

> webHttp行为中指定的默认格式

因此,如果您使用JSON请求调用REST服务,您将获得JSON.如果您使用POX请求调用它,您将获得XML.自动格式选择的完整描述在 MSDN .

翻译自:https://stackoverflow.com/questions/3719594/return-multiple-response-from-wcf


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Pro Git

Pro Git

Scott Chacon / Apress / 2009-8-27 / USD 34.99

Git is the version control system developed by Linus Torvalds for Linux kernel development. It took the open source world by storm since its inception in 2005, and is used by small development shops a......一起来看看 《Pro Git》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具