Weird behavior with WCF's Binding.BuildChannelFactory()

  • Thread starter Thread starter Ben
  • Start date Start date
B

Ben

Hi all,

I'm reading the book Essential WCF and while trying out the code listing at
page 95 I got an ArgumentException when running the code.
Here's the code listing:

BasicHttpBinding binding = new BasicHttpBinding();
BindingParameterCollection parameters = new
BindingParameterCollection();
Message m = Message.CreateMessage(MessageVersion.Soap11,
"urn:sendmessage");

IChannelFactory<IOutputChannel> factory =
binding.BuildChannelFactory<IOutputChannel>(parameters);

IOutputChannel channel = factory.CreateChannel(new
EndpointAddress("http://localhost/sendmessage/"));
channel.Send(m);
channel.Close();

factory.Close();

I tried to use some other channel types what nothing helped. I got an
exception all the time.
Then I looked at the stack trace and noticed that the exception is thrown
from the method TransactionFlowBindingElement.BuildChannelFactory. I fired up
Reflector and saw that this method internally calls the method
CanBuildChannelFactory of the same class. Inside this method there is this
check:

if ((((typeof(TChannel) != typeof(IOutputChannel)) && (typeof(TChannel) !=
typeof(IDuplexChannel))) && ((typeof(TChannel) != typeof(IRequestChannel)) &&
(typeof(TChannel) != typeof(IOutputSessionChannel)))) && ((typeof(TChannel)
!= typeof(IRequestSessionChannel)) && (typeof(TChannel) !=
typeof(IDuplexSessionChannel))))
{
return false;
}

Does this seem like a valid check? Shouldn't it be using || instead of all
the &&?

Perhaps I'm getting all this wrong and can't figure the code listing from
the book right.

Thanks,
Ben
 
I tried to do some workaround for this.
I created an interface that inherits from all the aforementioned interface
and guess what? It passed that method! But then it failed in some other
method down the codebase that didn't recognise it. Some serious voodoo.
 
Back
Top