Ray's playground

 

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.

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 }

 

 

posted on 2010-03-29 16:51  Ray Z  阅读(235)  评论(0编辑  收藏  举报

导航