<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      REST 架構(gòu)風(fēng)格下的WCF特性簡介

        REST(Representational State Transfer)作為一種優(yōu)秀的架構(gòu)風(fēng)格,自誕生以來越來越受廣大開發(fā)者的青睞。對沒有接觸過REST的開發(fā)人員,可以參閱本人的上一篇博客:對REST架構(gòu)的理解及Jquery+JSON+RESTful WCF 

      由于REST推崇的簡易型,以及基于HTTP協(xié)議的特點,它又有一些什么樣的特性呢。?本問將圍繞這個主題分兩部分展開,并結(jié)合Demo程序加以介紹。第一部分介紹涉及到的知識點,第二部分介紹Demo。


        主要涉及到的知識點如下:
        1、綁定協(xié)議與行為(webHttpBinding 與webHttpBehavior)
        2、Action的定義(POST、GET、DELETE、PUT)
        3、URI(Uniform Resource Identifier)的指定
        4、webServiceHost與webServiceHostFactory

      *1、綁定協(xié)議與行為(webHttpBinding 與webHttpBehavior)
      眾所周知,WCF中支持的協(xié)議有很多,如wsHttpBinding等ws-*系列的、netTcpBinding、支持MSMQ的系列協(xié)議等。在構(gòu)建REST架構(gòu)風(fēng)格的WCF中
      我們使用的協(xié)議為webHttpBinding 。與之相對應(yīng)的行為則是webHttpBehavior。

      MSDN對他們的的描述分別為:
      webHttpBinding:一個綁定,可用于為通過 HTTP 請求(而不是 SOAP 消息)公開的 Windows Communication Foundation (WCF) Web 服務(wù)配置終結(jié)點。
      webHttpBehavior:啟用 Windows Communication Foundation (WCF) 服務(wù)的 Web 編程模型。
      WebHttpBehavior 行為與 WebHttpBinding 綁定一起使用時,支持 WCF 公開和訪問 Web 樣式服務(wù)。WebServiceHost 會自動將此行為添加到使用 WebHttpBinding 的終結(jié)點。
      webHttpBinding作為REST 架構(gòu)風(fēng)格下的WCF 所使用的協(xié)議,它和其他協(xié)議一樣通知WCF如何為通訊建立通道堆棧,也就是建立相應(yīng)的Channel以用于
      通訊。webHttpBehavior的作用是為REST WCF的端點提供行為的配置,它決定了WebHttpDispatchOperationSelector如何決定選擇何種路由方式
      來訪問資源。
      *2、Action中的各個動詞決定了對資源進行何種操作。
      POST:對客戶端知曉的資源進行添加。它是WebInvokeAttribute默認的操作動作
      Get:對資源進行獲取。它是WebGetAttribute默認的操作動作
      DELETE:對資源進行刪除。一般由WebInvokeAttribute指定
      PUT:對資源進行添加或者修改。一般由WebInvokeAttribute指定

      *3、URI
      URI(Uniform Resource Identifier)的指定是通過REST WCF編程模型中的WebGetAttribute、 WebInvokeAttribute兩種特性來標識的。它通過將
      WebGetAttribute、 WebInvokeAttribute兩種特性的UriTemplate屬性指定。通常將它指定在服務(wù)契約對應(yīng)的接口上,WebHttpDispathOperationSelector通過URI來決定
      對資源進行操作。示例定義如下:
      [OperationContract]
      [WebGet(UriTemplate = "/")]
      List<LogEntity> GetAll();

      *4、webServiceHost與webServiceHostFactory
      對WCF有些了解的人都知道,它的配置是比較復(fù)雜的。REST所推崇的是簡易型,因此在REST WCF編程模型中,MS推出了webServiceHost
      與webServiceHostFactory來簡化我們的配置。webServiceHost繼承自ServiceHost,使用它,我們將不再需要對webHttpBinding與
      webHttpBehavior進行配置,webServiceHost會自動創(chuàng)建端點,并使用webHttpBinding與webHttpBehavior對其進行配置。
        MSDN中對webServiceHost的說明如下:
        如果 WebServiceHost 在服務(wù)說明中找不到終結(jié)點,則它將在服務(wù)的基址中自動為 HTTP 和 HTTPS 基址創(chuàng)建一個默認終結(jié)點。如果用戶已在基址中明確配置
      終結(jié)點,則它不會自動創(chuàng)建終結(jié)點。WebServiceHost 會自動配置終結(jié)點的綁定,以便在安全虛擬目錄中使用時與關(guān)聯(lián)的 Internet 信息服務(wù) (IIS) 安全設(shè)置一起使用。
      當創(chuàng)建默認 HTTP 終結(jié)點時,WebServiceHost 同時禁用 HTTP 幫助頁和 Web 服務(wù)描述語言 (WSDL) GET 功能,以使元數(shù)據(jù)終結(jié)點不干擾默認 HTTP 終結(jié)點。
        此外,WebServiceHost 類會將 WebHttpBehavior 添加到所有沒有該行為但具有 WebMessageEncodingElement 的終結(jié)點中。如果服務(wù)上的所有操作都具有空的 HTTP 請求正文,或者都將 HTTP 請求正文以流的形式處理,則 WebServiceHost 會自動為綁定配置適當?shù)膬?nèi)容類型映射器。
        請注意:在3.5中它會禁用REST WCF中的幫助(help)頁面。
      WebServiceHostFactory ,繼承自ServiceHostFactory,使用它,我們將無需對REST WCF進行配置,只需在svc文件的指令中指定它即可。示例如下:
      <%@ ServiceHost Service="LogServices.LogServices" Factory="System.ServiceModel.Activation.WebServiceHostFactory"%>
      需要說明的是:Service屬性需指明是實現(xiàn)服務(wù)契約的類。
      第二部分:Demo示例程序。
      開發(fā)環(huán)境:VS2008 SP1
      程序結(jié)構(gòu)如下圖:


      Contracts:定義了服務(wù)契約。
      代碼如下:

      [ServiceContract]
      public interface Ilog
      {
      [OperationContract]
      [WebGet(UriTemplate = "/")]
      List<LogEntity> GetAll();
      
      [OperationContract]
      [WebGet(UriTemplate = "Get/{year}/{month}")]
      List<LogEntity> GetMonthLog(string year,stringmonth);
      }
      [DataContract]
      public class LogEntity
      {
      [DataMember]
      public int ID { get; set; }
      
      [DataMember]
      public string EventName { get; set; }
      
      [DataMember]
      public string Level { get; set; }
      
      [DataMember]
      public DateTime Time { get; set; }
      
      }
      

        

      LogServices:實現(xiàn)服務(wù)契約,提供服務(wù)
      代碼如下:

      public List<LogEntity> GetAll()
      {
      return GetLogEntityList();
      }
      
      public List<LogEntity> GetMonthLog(string year, string month)
      {
      List<LogEntity> logEntities = GetLogEntityList();
      List<LogEntity> logList = new List<LogEntity>();
      logEntities.ForEach(log =>
      {
      if (log.Time.Year.ToString() == year && log.Time.Month.ToString() == month)
      {
      logList.Add(log);
      }
      });
      return logList;
      
      }
      

        

      順便大家可以看看配置文件,使用WebServiceHostFactory不需要對WCF進行配置。配置文件如下:

      <?xml version="1.0"?>
      <configuration>
      <configSections>
      <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
      <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
      <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
      <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
      <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
      </sectionGroup>
      </sectionGroup>
      </sectionGroup>
      </configSections>
      <appSettings/>
      <connectionStrings/>
      <system.web>
      <!-- 
      設(shè)置 compilation debug="true" 可將調(diào)試符號插入
      已編譯的頁面中。但由于這會 
      影響性能,因此只在開發(fā)過程中將此值 
      設(shè)置為 true。
      -->
      <compilation debug="true">
      <assemblies>
      <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
      <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
      <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
      </assemblies>
      </compilation>
      <!--
      通過 <authentication> 節(jié)可以配置 ASP.NET 用來 
      識別進入用戶的
      安全身份驗證模式。 
      -->
      <authentication mode="Windows"/>
      <!--
      如果在執(zhí)行請求的過程中出現(xiàn)未處理的錯誤,
      則通過 <customErrors> 節(jié)可以配置相應(yīng)的處理步驟。具體說來,
      開發(fā)人員通過該節(jié)可以配置
      要顯示的 html 錯誤頁
      以代替錯誤堆棧跟蹤。
      
      <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
      <error statusCode="403" redirect="NoAccess.htm" />
      <error statusCode="404" redirect="FileNotFound.htm" />
      </customErrors>
      -->
      <pages>
      <controls>
      <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </controls>
      </pages>
      <httpHandlers>
      <remove verb="*" path="*.asmx"/>
      <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
      </httpHandlers>
      <httpModules>
      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </httpModules>
      </system.web>
      <system.codedom>
      <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <providerOption name="CompilerVersion" value="v3.5"/>
      <providerOption name="WarnAsError" value="false"/>
      </compiler>
      </compilers>
      </system.codedom>
      <!-- 
      在 Internet 信息服務(wù) 7.0 下運行 ASP.NET AJAX 需要 system.webServer
      節(jié)。對早期版本的 IIS 來說則不需要此節(jié)。
      -->
      <system.webServer>
      <validation validateIntegratedModeConfiguration="false"/>
      <modules>
      <remove name="ScriptModule"/>
      <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </modules>
      <handlers>
      <remove name="WebServiceHandlerFactory-Integrated"/>
      <remove name="ScriptHandlerFactory"/>
      <remove name="ScriptHandlerFactoryAppServices"/>
      <remove name="ScriptResource"/>
      <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </handlers>
      </system.webServer>
      <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
      <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
      <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
      <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
      <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
      </dependentAssembly>
      </assemblyBinding>
      </runtime>
      <!--<system.serviceModel>
      
      </system.serviceModel>-->
      </configuration>
      

        

      RESTWCFDemo:寄宿服務(wù),并調(diào)用服務(wù)。由于REST WCF服務(wù)的寄宿需要IIS,所以程序的客戶端與服務(wù)端直接放在了一個Web工程下面。
      直接在IE中調(diào)用服務(wù)查看運行效果。
      1、調(diào)用List<LogEntity> GetAll()。結(jié)果如下圖:

      2、調(diào)用GetMonthLog。結(jié)果如下圖:

      posted @ 2011-10-26 11:21  tyb1222  閱讀(3425)  評論(4)    收藏  舉報
      主站蜘蛛池模板: 最近免费中文字幕大全免费版视频 | 国产精品日韩中文字幕熟女| 202丰满熟女妇大| 成人网站免费观看永久视频下载| 国产一级片内射在线视频| 国产福利片无码区在线观看| 综合色综合色综合色综合| 宅男噜噜噜66网站高清| 国产无遮挡又黄又爽在线视频| 中文字幕丰满乱子无码视频| 午夜DY888国产精品影院| 人人人澡人人肉久久精品| 成人国产精品免费网站| 伊人久久精品无码麻豆一区| 免费A级毛片樱桃视频| 成熟熟女国产精品一区二区| 国产精品亚洲综合久久小说| 精品国产欧美一区二区三区在线 | 中文字幕有码无码AV| 中文字幕日韩精品东京热| 最新日韩精品中文字幕| 九九在线精品国产| 日韩精品亚洲aⅴ在线影院| 免费观看国产女人高潮视频| 国产影片AV级毛片特别刺激| 乱人伦人妻中文字幕| 国产精品亚洲二区在线看| 我国产码在线观看av哈哈哈网站| 成人天堂资源www在线| 国产亚洲欧洲AⅤ综合一区| 少妇激情av一区二区三区| 在线观看热码亚洲av每日更新| 久久亚洲精精品中文字幕| 夜爽8888视频在线观看| 亚洲午夜香蕉久久精品| 精品一区二区亚洲国产| 少妇精品导航| 强奷白丝美女在线观看| 国产福利姬喷水福利在线观看| 蜜芽久久人人超碰爱香蕉| 国产精品中文字幕自拍|