一、定义契约
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
namespace Service.Interface
{
[ServiceContract]
public interface IFileUpLoad
{
[OperationContract]
string FileUpLoad();
}
}
二、实现契约
using Service.Dal;
using Service.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
namespace Service.Implement
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]
public class FileUpLoadService : IFileUpLoad
{
public string FileUpLoad()
{
return FileUpLoadAccessor.FileUpLoad();
}
}
}
会话,实例与并发
InstanceContextMode = InstanceContextMode.PerCall
在这种实例化模式下,客户端对服务方法的每一次调用,服务端都会new一个实例,方法调用结束即销毁,这种模式可能要频繁的花费创建对象和销毁对象的花销,因此性能比较差,但是每次调用后服务对象被销毁,对象所把持的资源也就被释放(如文件啦、数据库连接啦),因此伸缩性是最好的。