[WCF REST] 帮助页面与自动消息格式(JSON/XML)选择

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)选择

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值