Archives

Archives / 2008 / June
  • How to get implementation of IDispatchMessageFormatter

     class E4DBehaviorAttribute : Attribute , IOperationBehavior

        {

            #region IOperationBehavior Members

     

            public void AddBindingParameters (

                OperationDescription operationDescription ,

                BindingParameterCollection bindingParameters )

            {

            }

     

            public void ApplyClientBehavior (

                OperationDescription operationDescription ,

                ClientOperation clientOperation )

            {

            }

     

            public void ApplyDispatchBehavior (

                OperationDescription operationDescription ,

                DispatchOperation dispatchOperation )

            {

                DataContractSerializerOperationBehavior SerializerBehavior =

                    operationDescription

                        .Behaviors.Find<DataContractSerializerOperationBehavior>();

     

                if ( dispatchOperation.Formatter == null )

                {

                    ((IOperationBehavior)SerializerBehavior)

                        .ApplyDispatchBehavior (

                            operationDescription , dispatchOperation );

                }

                IDispatchMessageFormatter innerDispatchFormatter =

                                            dispatchOperation.Formatter;

     

     

                // Create Empty Message with IDispatchMessageFormatter

                Message msg = innerDispatchFormatter

                               .SerializeReply(

                                MessageVersion.Soap12 , new object[]{} , null );

     

                Console.WriteLine ( msg.ToString() );

            }

     

            public void Validate ( OperationDescription operationDescription )

            {

            }

     

            #endregion

        }

     

    Tip: Download WCF Visualizers.