WCF服务对于处理客户端连接的一点思考
2024-09-27 11:01:23
对于每个客户端的,服务端是否为每个客户端有专门的“通道”?
目的:想在服务端记录下来客户端的访问记录(进入、各个操作、离开等信息),并将其执行的操作独立记录在各个客户端对应的日志中。
下面是代码:
契约
[ServiceContract]
public interface IService
{ [OperationContract]
string GetData(string value); }
服务
public class Service : IService
{ public string GetData(string value)
{ string result = string.Format("Enter:{0}\t{1}\t{2}", value, GetClientIP(), AppDomain.CurrentDomain.ToString());
Log(result);
System.Threading.Thread.Sleep(); Log("Leave:{0}\t{1}", value, GetClientIP());
return result; }
}
客户端
System.Timers.Timer timer1 = new System.Timers.Timer();
timer1.Interval = ;
timer1.Elapsed +=
delegate
{
while (true)
{ ChannelFactory<IService> channelFatory = GetChannelFactory<IService>("BasicHttpBinding_IService1"); IService1 calculator = channelFatory.CreateChannel();
try
{
Console.WriteLine(calculator.GetData(IP));
}
finally
{
CloseConnection((calculator as ICommunicationObject));
} }
};
timer1.Start();
最后证明:服务为每个客户端连接开辟了单独的通道。不知道我的理解正确不。。。。待续
最新文章
- iOS UITableView , UITableViewController ,UITableViewCell实现全国各省市遍历,选择相应的地区
- BZOJ3293: [Cqoi2011]分金币
- 抄书 Copying Books UVa 714
- pH 值与曝气对硝化细菌硝化作用的影响
- chrome升级54以后,显示Adobe Flash Player 因过期而遭到阻止
- windows下 berkerly db的安装配置(修正了关键步骤)
- ASP.NET-FineUI开发实践-16(二)
- CXF之webservice
- GridBagLayout练习
- WCF订阅替换轮训
- webqq的注册登记和聊天页面--运用jsonp跨域
- PHP求解一个值是否为质数
- JSON 数据重复 出现$ref
- SQL优化指南
- properties文件操作
- 第 10 章 容器监控 - 079 - 监控利器 sysdig
- scrapy 爬取斗罗大陆漫画
- 在 C 代码中嵌入 Python 语句或使用 Python 模块 (Visual Studio 2013 环境设置)
- 跟我学SharePoint 2013视频培训课程——什么是SharePoint 2013(1)
- 2.6 CMMI2级——供应商协议管理(Supplier Agreement Management)