Mobile // Mobile Applications
Commentary
9/27/2008
12:00 AM
Commentary
Commentary
Commentary
50%
50%

Another WCF Gotcha: Calling Another Service/Resource Within a Call

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.  

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<ImContract>(webBinding, controlUri);
channel.Endpoint.Behaviors.Add(new WebHttpBehavior());
var proxy = channel.CreateChannel();
using( OperationContextScope((IContextChannel) proxy))
{
proxy.Dostuff()
}
I already spent the time figuring this bugger out. I hope this post will save you the trouble.

Comment  | 
Print  | 
More Insights
Building A Mobile Business Mindset
Building A Mobile Business Mindset
Among 688 respondents, 46% have deployed mobile apps, with an additional 24% planning to in the next year. Soon all apps will look like mobile apps and it's past time for those with no plans to get cracking.
Register for InformationWeek Newsletters
White Papers
Current Issue
InformationWeek Elite 100 Digital Issue, April 2015
The 27th annual ranking of the leading US users of business technology
Video
Slideshows
Twitter Feed
InformationWeek Radio
Archived InformationWeek Radio
. We've got a management crisis right now, and we've also got an engagement crisis. Could the two be linked? Tune in for the next installment of IT Life Radio, Wednesday May 20th at 3PM ET to find out.
Sponsored Live Streaming Video
Everything You've Been Told About Mobility Is Wrong
Attend this video symposium with Sean Wisdom, Global Director of Mobility Solutions, and learn about how you can harness powerful new products to mobilize your business potential.