1,创建服务契约类 :用接口来实现服务契约
1: using System.ServiceModel;
2: namespace Artech.WcfServices.Contracts
3: {
4: [ServiceContract(Name="CalculatorService", Namespace="http://www.artech.com/")]
5: public interface ICalculator
6: {
7: [OperationContract]
8: double Add(double x, double y);
9:
10: [OperationContract]
11: double Subtract(double x, double y);
12:
13: [OperationContract]
14: double Multiply(double x, double y);
15:
16: [OperationContract]
17: double Divide(double x, double y);
18: }
19: }
2,创建服务类:用服务类来实现服务契约接口类
1: using Artech.WcfServices.Contracts;
2: namespace Artech.WcfServices.Services
3: {
4: public class CalculatorService:ICalculator
5: {
6: public double Add(double x, double y)
7: {
8: return x + y;
9: }
10:
11: public double Subtract(double x, double y)
12: {
13: return x - y;
14: }
15:
16: public double Multiply(double x, double y)
17: {
18: return x * y;
19: }
20:
21: public double Divide(double x, double y)
22: {
23: return x / y;
24: }
25: }
26: }
3:通过自我寄宿的方式寄宿服务: