WCF(Windows Communication Foundation)是一系列支持数据通信的应用程序框架。
定义服务契约步骤:
1、新建类库,并引入程序集的System.ServiceModel
2、创建接口,定义服务契约,操作
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;//添加
namespace WCFHelloService
{
[ServiceContract]//用于类或结构上,用于指示WCF此类或结构能够被远程调用
public interface IHelloService
{
[OperationContract]//用于类中的方法(Method)上,用于指示WCF该方法可被远程调用
string SayHello(string name);
}
}
3、创建类,实现上面接口
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
namespace WCFHelloService
{
class HelloService:IHelloService
{
public string SayHello(string name)
{
return name + " say Hello!";
}
}
}