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
此頁面介紹此終結點上的服務操作。
| userID={userID} | GET | 根據UserID獲取用戶信息 |
轉載于:https://www.cnblogs.com/rosanshao/archive/2012/04/15/2450692.html
總結
以上是生活随笔為你收集整理的WCF HelpPage 和自动根据头返回JSON XML的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 13 款 JavaScript 模板引擎
- 下一篇: 安装Nginx时报错 the HTTP