as we know, WCF is designed by Microsoft for the SOA in the windows platform, but in my opinion , that to some extent violates the pricinple io SOA and also to some extent jeopardizes it.
As the some pinciples of SOA are concerned, a service should be state-less, it is expected to return the same result no matter which client calls it if the clients give the same input.
But WCF got three instant mode available:
- Per-Call
- Per-Session
- Singleton
Per-Call instance mode with a new instant by every call satisfies what the SOA requires, WCF create a absolute new instance for every call. so they don't affect each other anyway.
ex:
public class Calculator:ICalculator,IDisposable
{
double result;
public double Add(double x, double y)
{
this.result += x + y;
return x + y;
}
public double GetResult()
{
return this.result;
}
}
the above is set to Per-Call mode, so let's check the client code and its correspoding result.
MyClientCalculator proxy=MyClientCalculator ();
proxy.Add(1,1);
proxy.GetResult();//here print:2
proxy.Add(1,1);//again with the some input(1,1) as last one
proxy.GetResult();//here print:2,Note we get the same result with the same input.
Per-Session being a state-ware instant mode is not what the SOA requires, becasue all calls in a client share the only one instance. so maybe the fist call’s operation can affect the next call’s result. give a little code as exapmle(just the same code as the above but switch the instance mode to Per-Serssion):
public class Calculator:ICalculator,IDisposable
{
double result;
public double Add(double x, double y)
{
this.result += x + y;
return x + y;
}
public double GetResult()
{
return this.result;
}
}
the above is set to Per-serssion mode, so let's check the result again.
MyClientCalculator proxy=MyClientCalculator ();
proxy.Add(1,1);
proxy.GetResult();//here print:2
proxy.Add(1,1);//again with the some input(1,1) as last one
proxy.GetResult();//here print:4,Note we get the different result but with the same input.
I dont want to talk about the Singlton mode anyway, it is extremely much worse than the Per-session mode if the SOA is concerned. becasue Singleton mode makes all of the client share one instance. so thinking how it gonna look like
BTW, Per-call mode works well with the transaction, it is very complex when the mode comes to the Per-Session or Singleton.
Anyway, everything is possible if it exists. WCF is designed not only for the SOA, which makes it possible for us to make the classic ASP.NET application or client/server application.