Just hit an issue where I was using the WCF REST Starter kit and their wrapper methods for handling HttpWebRequest and HttpWebResponse for consuming ATOM. All was fine -- until I deployed. Then I was getting a securtiy exception.  So, I ported the code to use raw HttpWebRequest and all worked. My guess is that my provider has configured something to explicitly allow for HttpWebRequest but not wrapper methods around it. Or something. Anyway, here was my old code:

        private SyndicationFeed GetFeed(string url)
        {
            using (HttpClient http = new HttpClient())
            {
                using (HttpResponseMessage resp = http.Get(url))
                {
                    resp.EnsureStatusIsSuccessful();
                    return resp.Content.ReadAsSyndicationFeed();
                }
            }
        }
 

And here's my new code:

   private SyndicationFeed GetFeed(string url)
    {
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        {
            if (response == null)
                return null;
            if (response.StatusCode != HttpStatusCode.OK)
                return null;
            using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
            {
                try
                {
                    return SyndicationFeed.Load(reader);
                }
                catch (Exception)
                {
                    return null;
                }
            }
        }

Posted on June 19, 2010 16:47
Actions: E-mail | Comments (2)

Comments


alvinashcraft.com

alvinashcraft.com

June 19, 2010 08:22

Pingback from alvinashcraft.com

Dew Drop – June 20, 2010 | Alvin Ashcraft's Morning Dew


Sanjeev Agarwal

Sanjeev Agarwal

June 20, 2010 05:40

Daily tech links for .net and related technologies - June 21-23, 2010

Daily tech links for .net and related technologies - June 21-23, 2010 Web Development ASP.NET Internals


Add comment

Enter your name, handle, alias, or email.

We'll incarnate your avatar from the services below.