Should the WCF service remain open all the time?

I am creating a wcf service, my wcf service is now hosted in a console application as shown below.

 PersonService = new ServiceHost(typeof(PersonService));
 PersonService.AddServiceEndpoint(typeof(IPersonService), binding, "http://localhost:5645/PersonService");
 PersonService.Open();

Then I consume the wcf service using the ChannelFactory class;

EndpointAddress endPoint = new EndpointAddress("http://localhost:5645/PersonService");
ChannelFactory<IPersonService> engineFactory = new ChannelFactory<IPersonService>(binding, endPoint);
IPersonService personChannel = engineFactory.CreateChannel();

Then I can use this channel to call a method like

personChannel.GetPersonById("1");
personChannel.Close();

My question is:

As shown in the above code, the service always opens when the channel closes after completing work with it. Is it good behavior to open a service, or should I open a service and then close it on every call, given that I can have two clients calling the same service at the same time.

Please inform.

+3
source share
3 answers

, "" - , "Open" . , , . , .

, , () , .

. - , "" , . . . ( "" ) "" (.. ).

, / , . , , "" .

+5

, , .

+1

WCF services consume little resources, and working with 50 WCF services is not a problem. But please split the TCP port between them (number 5645in your case).

+1
source

All Articles