Basics(Essential Windows Communication Foundation)

  For the client to communicate meaningful information to the service, it needs to know the ABCs: the address, the binding, and the contract.

  Services can be hosted in any operating system process, from a console application running on a Windows desktop to an IIS server in a server farm. We showed an example of hosting in each. IIS is the most common mechanism for hosting WCF services. When .NET 3.5 is installed on an IIS server, requests for SVC resources are dispatched to WCF. The SVC file contains a reference to the service implementation. The implementation is either in a DLL in the /bin of the IIS virtual directory hosting the SVC file, in a DLL loaded into the global assembly cache (GAC) of the server, or it can be inline in source code in the SVC file.

ExpandedBlockStart.gif Service
 1  using  System;
 2  using  System.Collections.Generic;
 3  using  System.Linq;
 4  using  System.Text;
 5  using  System.ServiceModel;
 6 
 7  namespace  EssentialWCF
 8  {
 9      [ServiceContract]
10       public   interface  IStockService 
11      {
12          [OperationContract]
13           double  GetPrice( string  ticker);
14      }
15 
16       public   class  StockService : IStockService 
17      {
18           public   double  GetPrice( string  ticker) 
19          {
20               return   150 ;
21          }
22      }
23 
24       public   class  service
25      {
26           public   static   void  Main( string [] args)
27          {
28              ServiceHost serviceHost  =   new  ServiceHost( typeof (StockService),  new  Uri( " http://localhost:8000/EssentialWCF " ));
29 
30              serviceHost.AddServiceEndpoint( typeof (IStockService),  new  BasicHttpBinding(),  "" );
31              serviceHost.Open();
32              Console.WriteLine( " Press <ENTER> to terminate.\n\n " );
33              Console.ReadLine();
34 
35              serviceHost.Close();
36          }
37      }
38  }

 

 

转载于:https://www.cnblogs.com/zhtf2014/archive/2010/03/29/1699789.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值