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获取用户信息
posted on 2012-04-15 21:24  rosanshao  阅读(1798)  评论(0编辑  收藏  举报