Does ChannelFactory.CreateChannel () really open a connection?

This may be very dangerous, but after doing google alot was unable to come to any conclusion.

I want to know if ChannelFactory.CreateChannel () actually opens a connection or just returns something, and the actual connection will open the time of the method call. How long this connection will be alive if I do not close it. "

+4
source share
3 answers
Good question. When I wonder about something like this, I just read the .Net source code in there .

CreateChannel Open. CommunicationState Opened, Open DefaultOpenTimeout.

DefaultOpenTimeout .

.

+4

, :

// Sample service
public class Service : IService
{
   public void SendMessage(string message)
   {
      // do the processing....
   }
}

// Creating client connection using factory
// I can't remember the used of my asterisk here but this is use to identity the configuration name used for the endpoint.
var result = new ChannelFactory<IService>("*", new EndpointAddress(serviceAddress));
IService yourService = result.CreateChannel();

// This will automatically open a connection for you.
yourService.SendMessage("It works!");

// Close connection
result.Close();

:

<client>
      <!--note that there is no address on the endpoints as it will be overridden by the app anyway-->
      <endpoint binding="wsHttpBinding" bindingConfiguration="wsHttpBinding" behaviorConfiguration="standardBehavior" contract="IService" name="Service"/>
       .
       .
</client>

30 + , IIS. , WCF, , ChannetFactory , .

I used the Request Reply and .Net 4.5 message template here.

+1
source

All Articles