Windows / WCF Service and Threads, Beginners Question

We have a web service that sends requests to a Windows service that contains a WCF service for processing.

The interface is simple:

namespace MyApp
{
    [ServiceContract]
    public interface IMyApp
    {   
        [OperationContract]
        string DoSomething(string xml);
    }
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    class MyAppWcf : IMyApp
    {
        public string DoSomething(string xml) 
        { 
            Customer customer = GlobalObject.GetCustomer(xml); //millisecs 
            return customer.DoSomething(xml); //Takes 5-10 seconds
        }
    }
}

GlobalObject is created in WindowsService.OnStart () and contains all the static data that client objects need. The DoSomething () interface will be called up to approx. 30 different customers.

Questions:
1. What is the default behavior for the default? Will each call wait until the last is completed?
2. What will be the effect of InstanceContextMode?

REAL :
1000 , , . ,
DoSomething ( " 1" ); = > . 10
DoSomething ( " 2" ); = > .
DoSomething ( " 2" ); = > DoSomething ( " 2" ),

, ?

.

2: GlobalObject.GetCustomer() , XML, .

+3
2

OK. , , ConcurrencyMode PerCall instancing, , , PerCall instancing ConcurrencyMode. -, - . .

, , InstanceContextMode.PerCall, . .

  • 1 = > MyAppWcfInst.DoSomething( "<customer id=A/>" );
  • 2 = > MyAppWcfInst.DoSomething( "<customer id=B/>" );
  • 3 = > MyAppWcfInst.DoSomething( "<customer id=B/>" );

WCF , . , , . , Customer .

Client1 Client2 , Customer, Client3 Client2, "- " CustomerB. , Customer. , Customer.DoSomething() .

class Customer
{
    private object _sync = new object();

    public string DoSomething( string xml )
    {
        lock (_sync)
        {
            // put your logic here...
        }
    }
}

WCF-. , .

+2

PerCall , , MyAppWcf. , , .NET. Single, , ConcurrencyMode Multiple.

, GobalObject: , .

Customer.DoSomething, (, GlobalObject).

, " ". , .

+1

Source: https://habr.com/ru/post/1775666/


All Articles