tags:

views:

242

answers:

1

What really happens when a person calls the Open method of IRequestChannel? For example, if I have the following code:

ChannelFactory<IRequestChannel> factory = new ChannelFactory<IRequestChannel>();
// using a netTcpBinding to a net.tcp://localhost:9999/Bar
IRequestChannel outchannel = factory.CreateChannel();
outchannel.Open(); // what happens here?
if (outchannel.State == CommunicationState.Opened)
{
    success = true;
}
outchannel.Close();

I seem to get "false positives" on some services with accurate failures on others. I would assume I'd always get false positives if this didn't in some way verify that the channel was open.

Any suggestions on improvement? I'd like to avoid sending a message since this is just to test a service's viability for a diagnostic test but I can if that's necessary.


I noticed from our configuration file that the channels that return false positives are using the following behaviorConfiguration:

<binding name="secureNetTcpStream" maxBufferSize="2000000" maxReceivedMessageSize="2000000000" transferMode="Streamed" sendTimeout="00:05:00" receiveTimeout="14:00:00">
    <readerQuotas maxStringContentLength="2000000000" maxArrayLength="2000000000" />
    <security mode="TransportWithMessageCredential">
     <message clientCredentialType="UserName" />
    </security>
</binding>

I wonder if the streamed behavior configuration is what leads to the IRequestChannel showing it is open even when the host and service are unavailable?

+1  A: 

Calling the Open function will indeed contact the server side and will open the communication channel.

However, there might be situations when Open will succeed but calling one of the methods of the service will fail.

For example: If the client calls a service method that initiates a session and the server has reached its max sessions number then the function will fail with a server is busy exception. So you might fail creating a session even when you have an open channel.

There are other various failures that may be in a service even though the channel was opened successfully.

Summary: your check is good but there might be other "obstacles" that will interfere the client-server communication. These are probably your false positives...

Yuval Peled