I'm beginer in WCF. I created one WCF sample as below, but it didn't work correct.
WCF Service: ITestBiz:
[ServiceContract]
public interface ITestBiz
{
[OperationContract(IsOneWay = false)]
string Call(string clientName, int sleep);
[OperationContract(IsOneWay = true)]
void Call2(string clientName, int sleep);
}
TestBiz:
[ServiceBehavior(InstanceContextMode= InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]
public class TestBiz : ITestBiz
{
// maintain instance count
public int i=0;
public string Call(string ClientName, int sleep)
{
// increment instance counts
i++;
// display client name, instance number , thread number and time when
// the method was called
//Console.WriteLine("Client name :" + ClientName + "\t Instance:" +
// i.ToString() + "\t Thread:" + Thread.CurrentThread.ManagedThreadId.ToString() +
// "\t Time:" + DateTime.Now.ToString() + "\n\n");
string str ="Client name :" + ClientName + "\t Instance:" +
i.ToString() + "\t Thread:" + Thread.CurrentThread.ManagedThreadId.ToString() +
"\t Time:" + DateTime.Now.ToString() + "\n\n";
// Wait for 5 seconds
Thread.Sleep(sleep);
return str;
}
public void Call2(string ClientName, int sleep)
{
// increment instance counts
i++;
// display client name, instance number , thread number and time when
// the method was called
Console.WriteLine("Client name :" + ClientName + "\t Instance:" +
i.ToString() + "\t Thread:" + Thread.CurrentThread.ManagedThreadId.ToString() +
"\t Time:" + DateTime.Now.ToString() + "\n\n");
// Wait for 5 seconds
Thread.Sleep(sleep);
}
}
As you see, I'm testing with PerCall and Multiple concurrency.
With Call func, I set IsOneWay = false so that I can receive the string and show up my wcf client. And here is the result:
Client name :Client 1 Instance:1 Thread:19 Time:1/19/2015 4:20:34 PM
Client name :Client 1 Instance:1 Thread:19 Time:1/19/2015 4:20:34 PM
Client name :Client 1 Instance:1 Thread:19 Time:1/19/2015 4:20:35 PM
Client name :Client 1 Instance:1 Thread:19 Time:1/19/2015 4:20:35 PM
Client name :Client 1 Instance:1 Thread:19 Time:1/19/2015 4:20:36 PM
Client name :Client 1 Instance:1 Thread:19 Time:1/19/2015 4:20:36 PM
Client name :Client 1 Instance:1 Thread:19 Time:1/19/2015 4:20:37 PM
Client name :Client 1 Instance:1 Thread:19 Time:1/19/2015 4:20:37 PM
Client name :Client 1 Instance:1 Thread:19 Time:1/19/2015 4:20:38 PM
Client name :Client 1 Instance:1 Thread:19 Time:1/19/2015 4:20:38 PM
It always had the same thread. It meant there are NOT multiple threads in this case?
With Call2 func, I set IsOneWay = true, and when I debug on WCF Service, I see that the thread number is always different. It meant exist multiple threads.
I have no clue and no where to find the answer but this. Please advise.
Thank you very much.