[WCF REST] 帮助页面与自动消息格式(JSON/XML)选择
2013-05-23 15:40
302 查看
WCF REST 新建时默认HELP页面是关闭的。
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<!--
要在 REST 服务上实现 HTTP 缓存,需要做的配置如下
1、在 web.config 中的 system.web/caching 节点上为 REST 服务提供一个缓存配置
2、在方法上通过类似 [AspNetCacheProfile("Cache30S")] 的声明指定方法所使用的缓存配置
3、在 web.config 中的 system.serviceModel/serviceHostingEnvironment 节点上增加一个属性 aspNetCompatibilityEnabled="true" ,以启用 asp.net 兼容模式
4、在方法上使用如下声明,[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] ,以启用 asp.net 兼容模式
-->
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="Cache30S" duration="30" varyByParam="*" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
<serviceActivations>
<add relativeAddress="RestDemo.svc" service="ServiceLib.RestDemo" factory="System.ServiceModel.Activation.WebServiceHostFactory" />
</serviceActivations>
</serviceHostingEnvironment>
<!--
标准终结点是已经定义好相关配置的标准终结点
通过 kind 指定标准终结点
-->
<services>
<service name="ServiceLib.RestDemo">
<endpoint kind="webHttpEndpoint" contract="ServiceLib.IRestDemo" behaviorConfiguration="HelpBehavior" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<!--
启用 REST 的 Help 功能(在服务地址上加“/help”即可进入 REST 服务的帮助页面)
本例的 REST 服务的帮助页面为 http://localhost:14802/RestDemo.svc/help
-->
<behavior name="HelpBehavior">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
具体请见:
[WCF REST] 帮助页面与自动消息格式(JSON/XML)选择
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<!--
要在 REST 服务上实现 HTTP 缓存,需要做的配置如下
1、在 web.config 中的 system.web/caching 节点上为 REST 服务提供一个缓存配置
2、在方法上通过类似 [AspNetCacheProfile("Cache30S")] 的声明指定方法所使用的缓存配置
3、在 web.config 中的 system.serviceModel/serviceHostingEnvironment 节点上增加一个属性 aspNetCompatibilityEnabled="true" ,以启用 asp.net 兼容模式
4、在方法上使用如下声明,[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] ,以启用 asp.net 兼容模式
-->
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="Cache30S" duration="30" varyByParam="*" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
<serviceActivations>
<add relativeAddress="RestDemo.svc" service="ServiceLib.RestDemo" factory="System.ServiceModel.Activation.WebServiceHostFactory" />
</serviceActivations>
</serviceHostingEnvironment>
<!--
标准终结点是已经定义好相关配置的标准终结点
通过 kind 指定标准终结点
-->
<services>
<service name="ServiceLib.RestDemo">
<endpoint kind="webHttpEndpoint" contract="ServiceLib.IRestDemo" behaviorConfiguration="HelpBehavior" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<!--
启用 REST 的 Help 功能(在服务地址上加“/help”即可进入 REST 服务的帮助页面)
本例的 REST 服务的帮助页面为 http://localhost:14802/RestDemo.svc/help
-->
<behavior name="HelpBehavior">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
具体请见:
[WCF REST] 帮助页面与自动消息格式(JSON/XML)选择
相关文章推荐
- [转][WCF REST] 帮助页面与自动消息格式(JSON/XML)选择
- [WCF REST] 帮助页面与自动消息格式(JSON/XML)选择
- 【转】[WCF REST] 帮助页面与自动消息格式(JSON/XML)选择
- Comet4J(Comet for Java)是一个纯粹基于AJAX(XMLHTTPRequest)的服务器推送框架,消息以JSON方式传递,具备长轮询、长连接、自动选择三种工作模式。
- WCF--提示:异常消息为“传入消息的消息格式不应为“Raw”。此操作的消息格式应为 'Xml', 'Json'。
- WCF HelpPage 和自动根据头返回JSON XML
- WCF rest 的帮助页面和缓存机制
- 【.net 深呼吸】聊聊WCF服务返回XML或JSON格式数据
- WCF服务返回XML或JSON格式数据
- WCF中操作契约 BodyStyle和XML, Json格式的学习
- WCF服务返回XML或JSON格式数据
- SpringBoot RestController 同时支持返回xml和json格式数据
- SpringMVC4.x源码分析(六):消息转换器自动转换json、xml原理分析
- WCF REST 自动消息格式选择
- 不使用scriptmanager,以xml或json格式调用wcf服务的微软示例
- Dojo之调用数据源(json、xml等)页面自动解析显示
- 工作笔记:ajax json 同一jsp页面中,把java变量赋给js变量,如果java变量字符串符合json格式,则赋给js变量时,js变量会自动的变为json对象
- spring mvc 接收json、xml 数据格式,自动解析成对象
- 物流系统新版POST请求通过WCFREST服务:Json格式的http请求
- rest接口返回是比较灵活的,可以根据请求者的需求返回xml,json,string等格式