WCF Rest Service
VS2010——新建專案——聯機模板——WCF REST Service Template 40(CS)
url路由控制:實現/Service1訪問Service1類定義的服務
----------Web.config
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
</system.webServer>
<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" automaticFormatSelectionEnabled="true"/>
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
----------Global.asax.cs
public class Global : HttpApplication
{
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes();
}
private void RegisterRoutes()
{
// Edit the base address of Service1 by replacing the "Service1" string below
RouteTable.Routes.Add(new ServiceRoute("Service1", new WebServiceHostFactory(), typeof(Service1)));
}
}
----------Service1.cs
//通過Get方式訪問/Service1
[WebGet(UriTemplate = "")]
public List<SampleItem> GetCollection()
{
// TODO: Replace the current implementation to return a collection of SampleItem instances
return new List<SampleItem>() { new SampleItem() { Id = 1, StringValue = "Hello" } };
}
//通過Get方式訪問/Service1/213213
[WebGet(UriTemplate = "{id}")]
public SampleItem Get(string id)
{
return new SampleItem { Id = 12321, StringValue = "" };
}
//通過Post方式訪問/Service1/
[WebInvoke(UriTemplate = "", Method = "POST")]
public SampleItem Create(SampleItem instance)
{
return instance;
}
相關文章
- WCF、Web API、WCF REST、Web Service之區別WebAPIREST
- 構建WCF RESTful service示例REST
- WCF Security:Silverlight authentication for WCF service based on security token
- 十五天精通WCF——第十三天 用WCF來玩RestREST
- 利用WCF建立簡單的RESTFul ServiceREST
- WCF、Net remoting、Web service概念及區別REMWeb
- Web Service實踐之REST vs RPCWebRESTRPC
- WCF 的 Service Instance模式和併發處理模式
- WCF Data Service 使用小結 (一)—— 瞭解OData協議協議
- 在IIS8.5的環境下配置WCF的Restful ServiceREST
- WCF The service cannot be activated because it does not support ASP.NET compatibilityASP.NET
- ASP.NET MVC提交一個較複雜物件至WCF ServiceASP.NETMVC物件
- 誰能解釋一下 Rest style service的含義?REST
- 通過配置web.config使WCF向外提供HTTPS的Restful ServiceWebHTTPREST
- MSMQ In WCFMQ
- WCF學習筆記(一):WCF簡介筆記
- 【Rest】PUT Vs Post in RestREST
- 學習 WCF (3)--開發WCF客戶程式
- WCF筆記筆記
- WCF基礎
- REST is not enabled. use -rest to turn onREST
- WCF系列教程地址
- WCF配置檔案
- WCF基礎教程之開篇:建立、測試和呼叫WCF
- WCF分散式開發步步為贏(0):WCF學習經驗分享,如何更好地學習WCF?薦分散式
- REST APIsRESTAPI
- rest apiRESTAPI
- The REST ObjectionRESTObject
- REST真相REST
- 到底什麼樣的 REST 才是最佳 REST?REST
- SOA之(5)——REST的SOA(SOA with REST)概念REST
- WCF雙工通訊
- C# WCF入門C#
- WCF安全指南釋出
- WCF、Socket程式設計程式設計
- Java與WCF互動(一):Java客戶端呼叫WCF服務 (轉)Java客戶端
- WCF服務端的.NET Core支援專案Core WCF 正式啟動服務端
- REST : rest_framework.decorators.api_view 實現PATCHRESTFrameworkAPIView