I wrote in the past how WCF defaults limit scalability but this thing (which had cost me two days of head scratching) is even worse.
Consider the following scenario:
 You have a WCF service/resource. when you get a message/request your codes needs to send another message to another service.
Sounds common enough now doesn't it? and it is - unless you happen to use a service with   WebHttpBinding (e.g. if you try to develop a RESTful WCF service or want to use POX services).  When you use WebHttpBinding and try to make a call within a call you are likely to find yourself starring at a ProtocolException with a 405 error - Method not allowed. Turns out WCF finds itself confused by the Operation Context (OperationalContextScope) of the incoming request so if you want things to work properly you need to create a new one for the request
var webBinding = new WebHttpBinding();
var channel = new ChannelFactory(webBinding, controlUri);
channel.Endpoint.Behaviors.Add(new WebHttpBehavior());
var proxy = channel.CreateChannel();
using( new OperationContextScope((IContextChannel) proxy))
{
proxy.Dostuff()
}

I already spent the time figuring this bugger out- I hope this post will save you the trouble


 
Wednesday, October 15, 2008 8:27:38 AM (GMT Standard Time, UTC+00:00)
As a note to fellow developers that stumble unto this page.

The WebHttpBinding and Behavior classes are found in System.ServiceModel.Web.dll, took me a bit to figure that one out, since it's a seperate reference you have to add.

Also at the poster I'd like to note that the above code is missing the 'new' keyword inside the using statement.

Thanks for helping us figure it out! :-)
JoshK
Wednesday, October 15, 2008 9:04:42 AM (GMT Standard Time, UTC+00:00)
Hi Josh, You are right the "new" was missing. Thanks for pointing that out

Arnon
Comments are closed.