掃二維碼與項(xiàng)目經(jīng)理溝通
我們?cè)谖⑿派?4小時(shí)期待你的聲音
解答本文疑問/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流
對(duì)于WCF服務(wù)啟動(dòng)的方法,我們可以通過多種方式來實(shí)現(xiàn)。在這里我們將會(huì)通過一種特殊的方法來實(shí)現(xiàn)WCF服務(wù)啟動(dòng)。大家首先可以通過一段代碼示例來詳細(xì)分析一下這一服務(wù)的啟動(dòng)方法,以此加深這方面的印象。

專注于為中小企業(yè)提供網(wǎng)站制作、成都網(wǎng)站制作服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)隴縣免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了上千多家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
WCF服務(wù)啟動(dòng)代碼示例:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.ServiceModel;
- using System.ServiceModel.Description;
- namespace WCF1
- {
- [ServiceContract(Name = "MyService", Namespace =
"http://www.huisoftware.com")]- public class MyService
- {
- [OperationContract]
- public string MyMethod(string str)
- {
- return str + "Server Hello World";
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- using (ServiceHost host = new ServiceHost(typeof(MyService)))
- {
- host.AddServiceEndpoint(typeof(MyService), new WSHttpBinding(),
"http://127.0.0.1:8080/MyService");- if (host.Description.Behaviors.Find
() == null) - {
- ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
- behavior.HttpGetEnabled = true;
- behavior.HttpGetUrl = new Uri("http://127.0.0.1:8080
/MyService/metadata");- host.Description.Behaviors.Add(behavior);
- }
- host.Opened += delegate
- {
- Console.WriteLine("WCF服務(wù)已經(jīng)啟動(dòng)");
- };
- host.Open();
- Console.Read();
- }
- }
- }
- }
WCF服務(wù)啟動(dòng)的相關(guān)代碼就為大家介紹到這里。
【編輯推薦】

我們?cè)谖⑿派?4小時(shí)期待你的聲音
解答本文疑問/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流