MSFT, how do you expect people to follow you best practices, be productive on your platform, and create a great experience for customers if you publish horrible samples like this one. If a developer were to copy this code into a real application they would have just leaked two client connections, and it would take their user about ten minutes to hit the defaul connection limit. The code should look like this:
staticvoid Main(string[] args){
// Code not shown.
}
publicvoid Run(){
// This code is written by an application developer. // Create a channel factory. BasicHttpBinding myBinding = newBasicHttpBinding(); EndpointAddress myEndpoint = newEndpointAddress(http://localhost/MathService/Ep1);
// local variables that implement IDisposible should always be put in a using block
using (ChannelFactory<IMath> myChannelFactory = newChannelFactory<IMath>(myBinding, myEndpoint)) {
double s; // Create a channel. IMath wcfClient1 = myChannelFactory.CreateChannel(); try {
s = wcfClient1.Add(3, 39);
Console.WriteLine(s.ToString());}
finally {
// Make sure we close the channel when we're done.try {
((
IClientChannel)wcfClient1).Close(); }
catch (CommunicationException) {
// Ignore various exceptions regarding the Channel's current state }
catch (TimeoutException) {
// Ignore Timeouts }
}
// Create another channel.IMath wcfClient2 = myChannelFactory.CreateChannel(); try{
s = wcfClient2.Add(15, 27);
Console.WriteLine(s.ToString());}
finally {
try {
((
IClientChannel)wcfClient1).Close(); }
catch (CommunicationException) {
}
catch (TimeoutException) {
}
}
}
}