using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WCFService006.Contract006
{
using System.ServiceModel;
[ServiceContract(SessionMode = SessionMode.Allowed)]
public interface IHelloWCF
{
[OperationContract]
string PrintString(string s);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace WCFService006.Service006
{
using System.ServiceModel;
using WCFService006.Contract006;
//[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class HelloWCF : IHelloWCF, IDisposable
{
public HelloWCF()
{
StringBuilder builder = new StringBuilder();
builder.AppendLine();
builder.AppendLine("构造函数");
builder.AppendLine("当前时间:" + DateTime.Now.ToString());
builder.AppendLine("当前线程ID:" + Thread.CurrentThread.ManagedThreadId);
builder.AppendLine("是否使用线程池:" + Thread.CurrentThread.IsThreadPoolThread);
builder.AppendLine("是否使用后台线程:" + Thread.CurrentThread.IsBackground);
Console.WriteLine(builder.ToString());
}
~HelloWCF()
{
StringBuilder builder = new StringBuilder();
builder.AppendLine();
builder.AppendLine("析构函数");
builder.AppendLine("当前时间:" + DateTime.Now.ToString());
builder.AppendLine("当前线程ID:" + Thread.CurrentThread.ManagedThreadId);
builder.AppendLine("是否使用线程池:" + Thread.CurrentThread.IsThreadPoolThread);
builder.AppendLine("是否使用后台线程:" + Thread.CurrentThread.IsBackground);
Console.WriteLine(builder.ToString());
}
public void Dispose()
{
StringBuilder builder = new StringBuilder();
builder.AppendLine();
builder.AppendLine("Dispose函数");
builder.AppendLine("当前时间:" + DateTime.Now.ToString());
builder.AppendLine("当前线程ID:" + Thread.CurrentThread.ManagedThreadId);
builder.AppendLine("是否使用线程池:" + Thread.CurrentThread.IsThreadPoolThread);
builder.AppendLine("是否使用后台线程:" + Thread.CurrentThread.IsBackground);
Console.WriteLine(builder.ToString());
}
private int count;
public string PrintString(string s)
{
count++;
StringBuilder builder = new StringBuilder();
builder.AppendLine();
builder.AppendLine(String.Format("服务方法--Print({0})", s));
builder.AppendLine("服务器当前时间:" + DateTime.Now.ToString());
builder.AppendLine("当前线程ID:" + Thread.CurrentThread.ManagedThreadId);
builder.AppendLine("是否使用线程池:" + Thread.CurrentThread.IsThreadPoolThread);
builder.AppendLine("是否使用后台线程:" + Thread.CurrentThread.IsBackground);
Console.WriteLine(builder.ToString());
string str = String.Format("you called {0} times", count.ToString());
return str;
}
}
}

Host WCFService006 HelloWCF is Open
Endpoint 1
Address:http://127.0.0.1:6000/MyService006/HelloWCF
Binding:WSHttpBinding
Contract:WCFService006.Contract006.IHelloWCF
Contract ConfigurationName:WCFService006.Contract006.IHelloWCF
Endpoint 2
Address:http://127.0.0.1:6000/MyService006/mex
Binding:MetadataExchangeHttpBinding
Contract:System.ServiceModel.Description.IMetadataExchange
Contract ConfigurationName:IMetadataExchange
构造函数
当前时间:2018/5/30 0:27:23
当前线程ID:4
是否使用线程池:True
是否使用后台线程:True
服务方法--Print(Client1-1)
服务器当前时间:2018/5/30 0:27:23
当前线程ID:4
是否使用线程池:True
是否使用后台线程:True
Dispose函数
当前时间:2018/5/30 0:27:23
当前线程ID:4
是否使用线程池:True
是否使用后台线程:True
构造函数
当前时间:2018/5/30 0:27:23
当前线程ID:7
是否使用线程池:True
是否使用后台线程:True
服务方法--Print(Client1-2)
服务器当前时间:2018/5/30 0:27:23
当前线程ID:7
是否使用线程池:True
是否使用后台线程:True
Dispose函数
当前时间:2018/5/30 0:27:23
当前线程ID:7
是否使用线程池:True
是否使用后台线程:True
构造函数
当前时间:2018/5/30 0:27:24
当前线程ID:6
是否使用线程池:True
是否使用后台线程:True
服务方法--Print(Client2-1)
服务器当前时间:2018/5/30 0:27:24
当前线程ID:6
是否使用线程池:True
是否使用后台线程:True
Dispose函数
当前时间:2018/5/30 0:27:24
当前线程ID:6
是否使用线程池:True
是否使用后台线程:True
构造函数
当前时间:2018/5/30 0:27:24
当前线程ID:7
是否使用线程池:True
是否使用后台线程:True
服务方法--Print(Client2-2)
服务器当前时间:2018/5/30 0:27:24
当前线程ID:7
是否使用线程池:True
是否使用后台线程:True
Dispose函数
当前时间:2018/5/30 0:27:24
当前线程ID:7
是否使用线程池:True
是否使用后台线程:True
构造函数
当前时间:2018/5/30 0:27:24
当前线程ID:7
是否使用线程池:True
是否使用后台线程:True
析构函数
当前时间:2018/5/30 0:27:24
当前线程ID:2
是否使用线程池:False
是否使用后台线程:True
服务方法--Print(ChannelFactory1-1)
服务器当前时间:2018/5/30 0:27:24
当前线程ID:7
是否使用线程池:True
是否使用后台线程:True
析构函数
当前时间:2018/5/30 0:27:24
当前线程ID:2
是否使用线程池:False
是否使用后台线程:True
析构函数
当前时间:2018/5/30 0:27:24
当前线程ID:2
是否使用线程池:False
是否使用后台线程:True
析构函数
当前时间:2018/5/30 0:27:24
当前线程ID:2
是否使用线程池:False
是否使用后台线程:True
Dispose函数
当前时间:2018/5/30 0:27:24
当前线程ID:7
是否使用线程池:True
是否使用后台线程:True
构造函数
当前时间:2018/5/30 0:27:24
当前线程ID:4
是否使用线程池:True
是否使用后台线程:True
服务方法--Print(ChannelFactory1-2)
服务器当前时间:2018/5/30 0:27:24
当前线程ID:4
是否使用线程池:True
是否使用后台线程:True
Dispose函数
当前时间:2018/5/30 0:27:24
当前线程ID:4
是否使用线程池:True
是否使用后台线程:True

Host WCFService006 HelloWCF is Open
Endpoint 1
Address:http://127.0.0.1:6000/MyService006/HelloWCF
Binding:WSHttpBinding
Contract:WCFService006.Contract006.IHelloWCF
Contract ConfigurationName:WCFService006.Contract006.IHelloWCF
Endpoint 2
Address:http://127.0.0.1:6000/MyService006/mex
Binding:MetadataExchangeHttpBinding
Contract:System.ServiceModel.Description.IMetadataExchange
Contract ConfigurationName:IMetadataExchange
构造函数
当前时间:2018/5/30 0:26:14
当前线程ID:4
是否使用线程池:True
是否使用后台线程:True
服务方法--Print(Client1-1)
服务器当前时间:2018/5/30 0:26:14
当前线程ID:4
是否使用线程池:True
是否使用后台线程:True
服务方法--Print(Client1-2)
服务器当前时间:2018/5/30 0:26:14
当前线程ID:7
是否使用线程池:True
是否使用后台线程:True
Dispose函数
当前时间:2018/5/30 0:26:14
当前线程ID:6
是否使用线程池:True
是否使用后台线程:True
构造函数
当前时间:2018/5/30 0:26:16
当前线程ID:7
是否使用线程池:True
是否使用后台线程:True
服务方法--Print(Client2-1)
服务器当前时间:2018/5/30 0:26:16
当前线程ID:7
是否使用线程池:True
是否使用后台线程:True
服务方法--Print(Client2-2)
服务器当前时间:2018/5/30 0:26:16
当前线程ID:4
是否使用线程池:True
是否使用后台线程:True
Dispose函数
当前时间:2018/5/30 0:26:16
当前线程ID:7
是否使用线程池:True
是否使用后台线程:True
构造函数
当前时间:2018/5/30 0:26:17
当前线程ID:6
是否使用线程池:True
是否使用后台线程:True
析构函数
当前时间:2018/5/30 0:26:17
当前线程ID:2
是否使用线程池:False
是否使用后台线程:True
析构函数
当前时间:2018/5/30 0:26:17
当前线程ID:2
是否使用线程池:False
是否使用后台线程:True
服务方法--Print(ChannelFactory1-1)
服务器当前时间:2018/5/30 0:26:17
当前线程ID:6
是否使用线程池:True
是否使用后台线程:True
服务方法--Print(ChannelFactory1-2)
服务器当前时间:2018/5/30 0:26:17
当前线程ID:4
是否使用线程池:True
是否使用后台线程:True
Dispose函数
当前时间:2018/5/30 0:26:17
当前线程ID:6
是否使用线程池:True
是否使用后台线程:True

构造函数
当前时间:2018/5/30 0:24:53
当前线程ID:1
是否使用线程池:False
是否使用后台线程:False
Host WCFService006 HelloWCF is Open
Endpoint 1
Address:http://127.0.0.1:6000/MyService006/HelloWCF
Binding:WSHttpBinding
Contract:WCFService006.Contract006.IHelloWCF
Contract ConfigurationName:WCFService006.Contract006.IHelloWCF
Endpoint 2
Address:http://127.0.0.1:6000/MyService006/mex
Binding:MetadataExchangeHttpBinding
Contract:System.ServiceModel.Description.IMetadataExchange
Contract ConfigurationName:IMetadataExchange
服务方法--Print(Client1-1)
服务器当前时间:2018/5/30 0:25:04
当前线程ID:7
是否使用线程池:True
是否使用后台线程:True
服务方法--Print(Client1-2)
服务器当前时间:2018/5/30 0:25:04
当前线程ID:5
是否使用线程池:True
是否使用后台线程:True
服务方法--Print(Client2-1)
服务器当前时间:2018/5/30 0:25:05
当前线程ID:7
是否使用线程池:True
是否使用后台线程:True
服务方法--Print(Client2-2)
服务器当前时间:2018/5/30 0:25:05
当前线程ID:5
是否使用线程池:True
是否使用后台线程:True
服务方法--Print(ChannelFactory1-1)
服务器当前时间:2018/5/30 0:25:05
当前线程ID:6
是否使用线程池:True
是否使用后台线程:True
服务方法--Print(ChannelFactory1-2)
服务器当前时间:2018/5/30 0:25:05
当前线程ID:7
是否使用线程池:True
是否使用后台线程:True