none
July CTP - Guidance on factory close and message faults

    Question

  • It is always a good practice to close the channel factory once you are done. This practice leads to following code (with custom binding):


                    using (ChannelFactory<IClientEcho> factory = new ChannelFactory<IClientEcho>(binding, remoteEndPoint))
                    {
                        //Create proxy and call its method
                        IClientEcho proxy = factory.CreateChannel();
                        responseString = proxy.ClientHello(requestString);
                    }

    However if the service call fails with MessageSecurityException (for example), the end of using block throws a completely different exception (CommunicationObjectFaultedException). To avoid this different exception, one has to write the code that does not use using block and write the code to close only if there is no message fault. In other words, the simplicity of using block is lost.

    I am wondering why does not channel simply close without throwing its own error. I checked that CommunicationObjectFaultedException's inner exception is not populated with true exception is either.

    Any comments?


    Monday, August 07, 2006 7:39 PM

Answers

  • we had similar discussion internally,for now,we have to follow this guidence,we are considering to review this behavior again for v2:

     

    SUMMARY OF OUR INTERNAL DISCUSSION:

     

    1) This behavior has gone under serious debate with (at least) many hundreds of people

    2) The current behavior is the V1 behavior that we are shipping

    3) using() should only be used for non-production applications (POC, etc). Production apps should use the try {…;Close();} catch (CommunicationException) {Abort();} catch (TimeoutException) {Abort();} paradigm that is being used in the latest SDK samples
    Thursday, August 10, 2006 11:07 PM

All replies

  • we had similar discussion internally,for now,we have to follow this guidence,we are considering to review this behavior again for v2:

     

    SUMMARY OF OUR INTERNAL DISCUSSION:

     

    1) This behavior has gone under serious debate with (at least) many hundreds of people

    2) The current behavior is the V1 behavior that we are shipping

    3) using() should only be used for non-production applications (POC, etc). Production apps should use the try {…;Close();} catch (CommunicationException) {Abort();} catch (TimeoutException) {Abort();} paradigm that is being used in the latest SDK samples
    Thursday, August 10, 2006 11:07 PM
  • Thank you for the guidance.
    Thursday, August 10, 2006 11:24 PM
  •  Isn't using supposed to be the correct way to be sure that proper clean up happens?

    Is it a problem with the implementation of dispose?

    Friday, August 11, 2006 1:17 PM