标签:
using System; using System.ServiceModel; using System.Threading; namespace EssentialWCF { [ServiceContract] public interface IGoodStockService { [OperationContract] double GetStockPrice(string ticker); } [ServiceContract] public interface IGreatStockService { [OperationContract] double GetStockPriceFast(string ticker); } [ServiceContract] public interface IALLStockServices : IGoodStockService, IGreatStockService{}; public class AllStockServices : IALLStockServices { public double GetStockPrice(string ticker) { Thread.Sleep(5000); return 94.85; } public double GetStockPriceFast(string ticker) { return 94.85; } } }
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.serviceModel> <services> <service name ="EssentialWCF.StockServices" behaviorConfiguration="mexServiceBehavior"> <host> <baseAddresses> <add baseAddress="http://localhost:8000/EssentialWCF"/> </baseAddresses> </host> <endpoint name="GoodStockService" binding="basicHttpBinding" contract="EssentialWCF.IGoodStockService"/> <endpoint name="BetterStockService" address="better" binding="basicHttpBinding" contract="EssentialWCF.IGreatStockService"/> <endpoint name="BestStockService" address="best" binding="wsHttpBinding" contract="EssentialWCF.IGreatStockService"/> <endpoint name="AllStockServices" address="all" binding ="wsHttpBinding" contract="EssentialWCF.IAllStockServices"/> <endpoint name ="mex" binding ="mexHttpBinding" contract="IMetadataExchange" </service> </services> </system.serviceModel> </configuration>
using (localhost.GreatStockServiceClient proxy = new Client.localhost.GreatStockServiceClient("BetterStockService")) { Console.WriteLine(proxy.GetStockPriceFast("MSFT")); } using (localhost.GreatStockServiceClient proxy = new Client.localhost.GreatStockServiceClient("BestStockService")) { Console.WriteLine(proxy.GetStockPriceFast("MSFT")); }
标签:
原文地址:http://www.cnblogs.com/zeroone/p/4337618.html