zoukankan      html  css  js  c++  java
  • WCF HelpPage 和自动根据头返回JSON XML

    WCF

    通过Web.config设置,

    1 automaticFormatSelectionEnabled项便可实现返回内容自动根据Content-Type和Accept 返回JSON或者XML

    2helpEnabled="true"实现 HelpPage,在接口加Description特性

    <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
        <standardEndpoints>
          <webHttpEndpoint>
            <!--
                Configure the WCF REST service base address via the global.asax.cs file and the default endpoint
                via the attributes on the <standardEndpoint> element below
            -->
            <standardEndpoint name="" helpEnabled="true" defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true"/>
          </webHttpEndpoint>
        </standardEndpoints>
      </system.serviceModel>

     [ServiceContract]
        public interface IUserService : IBaseWCFService
        {
            [WebGet(UriTemplate = "userID={userID}")]
            [Description("根据UserID获取用户信息")]
            UserInfo GetUserInfo(string userID);
        }

    注册服务节点 RouteTable.Routes.Add(new ServiceRoute("Services/UserService", new WebServiceHostFactory(), typeof(UserService)));

    http://localhost:30760/Services/UserService/help

    此页面介绍此终结点上的服务操作。

    Uri方法描述
    userID={userID} GET 根据UserID获取用户信息
  • 相关阅读:
    浅谈prufer编码
    数据结构训练之三
    博弈论训练之一
    动态规划训练之十三
    杂题训练之七
    奇技淫巧训练之八
    浅谈博弈论
    浅谈卡特兰数
    奇技淫巧训练之七
    浅谈概率期望的一些例题
  • 原文地址:https://www.cnblogs.com/rosanshao/p/2450692.html
Copyright © 2011-2022 走看看