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.
source
share