[Mono-dev] (WCF) Binding elements order

Thiago Padilha tpadilha84 at gmail.com
Wed Jul 7 06:30:11 EDT 2010


  Hi,

  Try this test on both plataforms :

       [Test]
       [ExpectedExceptionAttribute(typeof(InvalidOperationException))]
       public void BuildChannelListenerThrowsIfOrderIsIncorrect ()
       {
                        BindingElement[] bindingElements = new
BindingElement[2];
			bindingElements[1] = new WebMessageEncodingBindingElement ();
			bindingElements[0] = new HttpTransportBindingElement ();
			
			CustomBinding binding = new CustomBinding (bindingElements);
			
			IChannelListener<IReplyChannel> listener =
binding.BuildChannelListener<IReplyChannel> (new Uri
("http://127.0.0.1/"), new BindingParameterCollection ());
       }

  It seems on Mono this runs fine, however on .NET it thows an
InvalidOperationException (
http://msdn.microsoft.com/en-us/library/ms405447.aspx ).
  I got confused about having to sort the elements in
'CreateBindingElements'. It seems that should be done only when
writing custom binding profiles. If the user uses 'CustomBinding'
directly, then he must pass the elements in the correct order.

On Wed, Jul 7, 2010 at 2:49 AM, Atsushi Eno
<atsushieno at veritas-vos-liberabit.com> wrote:
> Hello Thiago,
>
> In what kind of situation does this bring an issue? Is it like, a binding
> element after a
> TransportBindingElement should not be ignored under certain usage?
>
> For reference, there is a test named BuildChannelFactoryIgnoresRemaining()
> in HttpTransportBindingElementTest in our nunit test that confirms that
> InvalidBindingElement is ignored after a transport binding element. (If it
> is not ignored and called BuildChannelFactory<T>(), then it throws
> NotSupportedException.)
>
>        [Test]
>        public void BuildChannelFactoryIgnoresRemaining ()
>        {
>            BindingContext ctx = new BindingContext (
>                new CustomBinding (
>                    new HttpTransportBindingElement (),
>                    new InvalidBindingElement ()),
>                empty_params);
>            ctx.BuildInnerChannelFactory<IRequestChannel> ();
>        }
>
> Atsushi Eno
>
> On 2010/07/06 21:34, Thiago Padilha wrote:
>>
>>   Hi Atsushi,
>>
>>   While examining the file "Binding.cs" I found the following comment
>> on the two overloads of "CreateContext" method :
>>
>> "
>> // FIXME: it seems that binding elements are
>> // "validated" so that the last item is a transport.
>> "
>>   If you were unsure about where the binding elements should be
>> ordered take a look at this :
>>
>> http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.binding.createbindingelements.aspx
>>   According to this document, the ordering should be done inside the
>> "CreateBindingElements" method for any class that inherits from
>> "Binding". This could be fixed by using the following code in
>> "CustomBinding.cs" :
>>
>> public override BindingElementCollection CreateBindingElements ()
>>                {
>>                        return new BindingElementCollection
>> (elements.OrderBy (be =>
>>                        {
>>                                Type t = be.GetType ();
>>                                if
>> (typeof(TransportBindingElement).IsAssignableFrom (t))
>>                                        return 2;
>>                                if
>> (typeof(MessageEncodingBindingElement).IsAssignableFrom (t))
>>                                        return 1;
>>                                return 0;
>>                        }));
>>                }
>> _______________________________________________
>> Mono-devel-list mailing list
>> Mono-devel-list at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>>
>>
>>
>>
>
>


More information about the Mono-devel-list mailing list