在WCF初探-8:WCF服务承载 (上)中,我们对宿主的概念、环境、特点做了文字性的介绍和概括,接下来我们将通过实例对这几种寄宿方式进行介绍。为了更好的说明各寄宿环境特点,本实例采用Http和net.tcp两种服务通讯方式,同时寄宿在不同的宿主中。程序结构如下:
服务契约的接口和实现代码如下:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel; namespace Service { [ServiceContract] public interface IServiceCalculator { [OperationContract] double Add(double n1, double n2); } }