内容简介:翻译自: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
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Design systems
Not all design systems are equally effective. Some can generate coherent user experiences, others produce confusing patchwork designs. Some inspire teams to contribute to them, others are neglected. S......一起来看看 《Design systems》 这本书的介绍吧!