WCF自托管宿主是什么

這篇文章主要講解了“WCF自托管宿主是什么”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“WCF自托管宿主是什么”吧!

創(chuàng)新互聯(lián)公司是一家專業(yè)提供東乃企業(yè)網站建設,專注與成都網站建設、成都做網站html5、小程序制作等業(yè)務。10年已為東乃眾多企業(yè)、政府機構等服務。創(chuàng)新互聯(lián)專業(yè)網絡公司優(yōu)惠進行中。

利用WCF提供的ServiceHost<T>提供的Open()和Close()方法,可以便于開發(fā)者在控制臺應用程序,Windows應用程序乃至于ASP.NET應用程序中托管服務。不管自宿主的環(huán)境是何種應用程序,實質上托管服務的方式都是一致的。例如在控制臺應用程序中:

using (ServiceHost host = new ServiceHost(typeof(DocumentsExplorerService)))   {   host.Open();    Console.WriteLine("The Service had been launched.");   Console.Read();   }

ServiceHost實例是被創(chuàng)建在應用程序域中,因此我們必須保證宿主進程在調用服務期間不會被關閉,因此我們利用Console.Read() 來阻塞進程,以使得控制臺應用程序能夠一直運行,直到認為地關閉應用程序。如果是Windows應用程序,則可以將創(chuàng)建ServiceHost實例的代碼放在主窗體的相關代碼中,保證服務WCF自托管宿主不會被關閉。相應地,我們需要配置應用程序的app.config配置文件:

<configuration>   <system.serviceModel>   <services>   <service name="BruceZhang.WCF.DocumentsExplorerServiceImplementation.DocumentsExplorerService" behaviorConfiguration="DocumentExplorerServiceBehavior">   <host>   <baseAddresses>   <add baseAddress="http://localhost:8008/DocumentExplorerService"/>   </baseAddresses>   </host>   <endpoint   address=""   binding="basicHttpBinding"   bindingConfiguration="DocumentExplorerServiceBinding"   contract="BruceZhang.WCF.DocumentsExplorerServiceContract.IDocumentsExplorerService"/>   <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>   </service>   </services>   <bindings>   <basicHttpBinding>   <binding name="DocumentExplorerServiceBinding" sendTimeout="00:10:00" transferMode="Streamed"   messageEncoding="Text" textEncoding="utf-8" maxReceivedMessageSize="9223372036854775807">   </binding>   </basicHttpBinding>   </bindings>   <behaviors>   <serviceBehaviors>   <behavior name="DocumentExplorerServiceBehavior">   <serviceMetadata httpGetEnabled="true"/>   </behavior>   </serviceBehaviors>   </behaviors>   </system.serviceModel>   </configuration>

注意,配置文件中的服務名必須包含服務契約以及服務類的命名空間。此外,在配置文件中我通過<baseAddresses>標簽為服務添加了基地址,因此在endpoint中,address為""。

感謝各位的閱讀,以上就是“WCF自托管宿主是什么”的內容了,經過本文的學習后,相信大家對WCF自托管宿主是什么這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關知識點的文章,歡迎關注!

網站題目:WCF自托管宿主是什么
網站地址:http://bm7419.com/article46/geghhg.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供商城網站、電子商務、定制開發(fā)App開發(fā)、軟件開發(fā)品牌網站制作

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司