您的位置:首页 > Web前端 > JavaScript

[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)选择
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐