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获取用户信息
  • 相关阅读:
    数独
    canvas生成图片并保存到本地文件夹主要代码
    2048未完成
    Page
    IDEA新建MAVEN项目时速度缓慢
    Bug 记录(持续更新。。。)
    RecyclerBaseAdapter 和 OnItemClickListener
    AutoLoadRecyclerView
    BaseActionBarActivity
    Volley + OkHttp3 + Gson 组合的简单网络请求封装
  • 原文地址:https://www.cnblogs.com/rosanshao/p/2450692.html
Copyright © 2011-2022 走看看