Q: InstanceContextMode.PerCall acts as a InstanceContextMode.Single in wcf I am trying to create a wcf service host with the help of code only(no config is involved).
I have a static int and InstanceContextMode.PerCall set for the wcftestservice. As per the tutorial provided on the internet, I should be having same value for every call to the wcf?
Note: I have tested this behavior in console application as well as windows service and I am testing the behavior with the help of wcf test client
Here is the code:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class WcfServiceTest : IContract
{
    static int _counter;
    public string GetData(string p1)
    {
        return Convert.ToString(_counter++);
    }
}

Contract: 
[ServiceContract]
public interface IContract
{
    [OperationContract]
    string GetData(string p1);
}

The service host code:
    static ServiceHost _servicehost;

    static void Main(string[] args)
    {
        string tcpPort = "8081";
        string httpPort = "8888";
        string urlWithoutProtocol = "{0}://localhost:{1}/WcfServiceTest";
        string netTcpAddress = string.Format(urlWithoutProtocol, "net.tcp", tcpPort);
        string httpAddress = string.Format(urlWithoutProtocol, "http", httpPort);

        string netTcpMexAddress = netTcpAddress + "/mex";
        string httpMexAddress = httpAddress + "/mex";
        if (_servicehost != null)
        {
            _servicehost.Close();
        }
        _servicehost = new ServiceHost(typeof(wcftest.WcfServiceTest));
        ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
        //smb.HttpGetUrl = httpUri;
        //smb.HttpGetEnabled = true;
        _servicehost.Description.Behaviors.Add(smb);
        _servicehost.AddServiceEndpoint(typeof(wcftestcontract.IContract), new NetTcpBinding(), netTcpAddress);
        Binding mexTcpBinding = MetadataExchangeBindings.CreateMexTcpBinding();
        _servicehost.AddServiceEndpoint(typeof(IMetadataExchange), mexTcpBinding, netTcpMexAddress);

        _servicehost.AddServiceEndpoint(typeof(wcftestcontract.IContract), new BasicHttpBinding(), httpAddress);
        Binding mexHttpBinding = MetadataExchangeBindings.CreateMexHttpBinding();
        _servicehost.AddServiceEndpoint(typeof(IMetadataExchange), mexHttpBinding, httpMexAddress);

        _servicehost.Open();
        Console.ReadKey();
    }


A: If you want to check that it creates only once for Singleton mode, and each time for PerCall mode, then you need to increment your variable in constructor:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class WcfServiceTest : IContract
{
    static int _counter;

    public WcfServiceTest()
    {
        _counter++;
    }
    public string GetData(string p1)
    {
        return Convert.ToString(_counter);
    }
}

Then for each call number will increase for PerCall, and it won't increase for Singleton mode
Yes, tutorial has a bug. In their sample should be this without static modifier:
[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]
public class MyService:IMyService
{
    int m_Counter = 0;

    public int MyMethod()
    {
        m_Counter++;
        return m_Counter;
    }       
}

Static variable means that it should be the same for all instances of object. So, for static variable there is no difference between PerCall and Signleton modes, as it will be the same.
