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

InformationWeek is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them.Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

IoT
IoT
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.

We welcome your comments on this topic on our social media channels, or [contact us directly] with questions about the site.
Comment  | 
Print  | 
More Insights
Slideshows
IT Careers: 10 Industries with Job Openings Right Now
Cynthia Harvey, Freelance Journalist, InformationWeek,  5/27/2020
Commentary
How 5G Rollout May Benefit Businesses More than Consumers
Joao-Pierre S. Ruth, Senior Writer,  5/21/2020
News
IT Leadership in Education: Getting Online School Right
Jessica Davis, Senior Editor, Enterprise Apps,  5/20/2020
White Papers
Register for InformationWeek Newsletters
Video
Current Issue
Key to Cloud Success: The Right Management
This IT Trend highlights some of the steps IT teams can take to keep their cloud environments running in a safe, efficient manner.
Slideshows
Flash Poll