Click here to Skip to main content
12,765,345 members (36,717 online)
Click here to Skip to main content


85 bookmarked
Posted 31 Jul 2011

Tweaking WCF to build highly scalable async REST API

, 31 Jul 2011 CPOL
You can build async REST API using WCF but due to some bug in WCF implementation it does not scale as you would want it to. Here's my journey with Microsoft's WCF team to explore the problem and find the right fix.
/// Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.ServiceModel.Activation;
//using Microsoft.ServiceModel.Web;
using System.Linq;
using System.Net;
using System.IO;
using System.Text;
using ProxyStuff;
using System.Web;

// The following line sets the default namespace for DataContract serialized typed to be ""
[assembly: ContractNamespace("", ClrNamespace = "WcfAsyncRestApi")]
namespace WcfAsyncRestApi
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple),
    AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed),
    public partial class RegularService
        /// <summary>
        /// Returns the content from destination URL and caches the response in the browser for specified seconds.
        /// </summary>
        /// <param name="url">URL to fetch</param>
        /// <param name="cacheDuration">Cache duration</param>
        /// <returns></returns>
        //[WebGet(BodyStyle = WebMessageBodyStyle.Bare, UriTemplate="/Url?uri={url}&cacheDuration={cacheDuration}")]
        public Stream GetUrl(string url, int cacheDuration)
            using (WebClient client = new WebClient())
                return new MemoryStream(client.DownloadData(url));


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 31 Jul 2011
Article Copyright 2011 by Omar Al Zabir
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid