There are some ways to hosting WCF service as below:

1. IIS; 2. Console App; 3. Window Service
Using Console Application to host WCF service:
Step 1:

Step 2: Add a Class Library project : 'Contract'
Step 3: Add a Interface : 'IHelloWorld'
using System.ServiceModel;
namespace Contract
{
[ServiceContract(Name= "HelloWorldService")]
public interface IHelloWorld
{
[OperationContract]
string SayHello();
}
}Step 4: Add a Class : 'HelloWorld'
namespace Contract
{
public class HelloWorld : IHelloWorld
{
public string SayHello()
{
return "Hello World. I'm WCF Service.";
}
}
}Step 5: Add a Console Application : 'Host'
Step 6:
Use WCF Service Configuration Editor to generate the server config.
<?xml version="1.0" encoding="utf-8"?><configuration> <system.serviceModel> <behaviors> <serviceBehaviors> <behaviorname="HelloWorldBehavior"> <serviceMetadatahttpGetEnabled="true" /> </behavior> </serviceBehaviors> </behaviors> <services> <servicebehaviorConfiguration="HelloWorldBehavior" name="Contract.HelloWorld"> <endpointaddress="http://localhost:9999/HelloWorldService" binding="basicHttpBinding"
bindingConfiguration="" contract="Contract.IHelloWorld" /> <host> <baseAddresses> <addbaseAddress="http://localhost:9999/HelloWorldService" /> </baseAddresses> </host> </service> </services> </system.serviceModel></configuration>Step 7:
Set up server host
using System;
using System.ServiceModel;
using Contract;
namespace Host
{
class Program
{
static void Main(string[] args)
{
using (var host = new ServiceHost(typeof(HelloWorld)))
{
host.Opened+= delegate
{
Console.WriteLine("CalculaorService已經(jīng)啟動,按任意鍵終止服務(wù)!");
};
host.Open();
Console.Read();
}
}
}
}
本文名稱:HostingWCFService-創(chuàng)新互聯(lián)
網(wǎng)頁網(wǎng)址:http://www.chinadenli.net/article8/djohip.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設(shè)、網(wǎng)站營銷、全網(wǎng)營銷推廣、網(wǎng)站策劃、企業(yè)建站、域名注冊
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容