Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 332869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:54:29+00:00 2026-05-12T09:54:29+00:00

I’m trying to use async workflows in F# to fetch several web requests. However,

  • 0

I’m trying to use async workflows in F# to fetch several web requests.

However, some of my requests are occasionally returning errors (e.g. http 500), and I don’t know how to handle this. It appears like my F# program gets stuck in an infinite loop when running in the debugger.

I’m probably missing some stuff, cause examples I seen didn’t compile out of the box. First thing I found that helped was this bit of code:

type System.Net.WebRequest with
  member req.GetResponseAsync() =
    Async.BuildPrimitive(req.BeginGetResponse, req.EndGetResponse)

and then I have my bit of code to fetch the requests, which is pretty standard from examples I’ve seen:

let async_value = async {
  let req = WebRequest.Create(url)
  let! rsp = req.GetResponseAsync()
  return (rsp :?> HttpWebResponse).StatusCode
}

and then I try to get the result:

let status = Async.RunSynchronously(async_value)

But when I run my program in debugger, it breaks at req.EndGetResponse because server returned internal server error 500. If I keep just continuing execution, it gets in a funky loop, breaking at req.EndGetResponse (sometimes several in a row), and at let status = Async.RunSynchronously(async_value).

How do I get around the exception problem so I can get my status code? Also, do I need the type thing I did above? Or am I missing some library/dll for F#/VS 2010 Beta 1, of which this is already a part of?

I actually run several requests in parallel, using Async.RunSynchronously(Async.Parallel(my_array_of_async_values)), though I don’t think that is related to the exception issue I’m having.

The fact the examples I’ve come across only use Async.Run rather than Async.RunSynchronously is probably an indicator I’m missing something… =/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T09:54:29+00:00Added an answer on May 12, 2026 at 9:54 am

    It’s now called ‘AsyncGetResponse’ (no longer ‘GetResponseAsync’). And ‘Run’ was renamed to ‘RunSynchronously’. So I don’t think you’re missing anything substantial here, just name changes in the latest release.

    What are your debugger settings with regard to “Tools\Options\Debugging\General\Enable Just My Code” and “Debug\Exceptions” (e.g. set to break when any first-chance CLR exception is thrown or not)? I am unclear if your question involves the program behavior, or the VS tooling behavior (sounds like the latter). This is further confounded by the fact that breakpoint/debugging ‘locations’ in F# Beta1 have some bugs, especially regarding async workflows, which means that the behavior you see in the debugger may look a little strange even if the program is executing properly…

    Are you using VS2008 CTP or VS2010 Beta1?

    In any case, it appears the exception due to a 500 response is expected, this is how WebRequest works. Here’s a short demo program:

    open System
    open System.ServiceModel 
    open System.ServiceModel.Web 
    
    [<ServiceContract>]
    type IMyContract =
        [<OperationContract>]
        [<WebGet(UriTemplate="/Returns500")>]
        abstract Returns500 : unit -> unit
        [<OperationContract>]
        [<WebGet(UriTemplate="/Returns201")>]
        abstract Returns201 : unit -> unit
    
    type MyService() =
        interface IMyContract with
            member this.Returns500() =
                WebOperationContext.Current.OutgoingResponse.StatusCode <- 
                    System.Net.HttpStatusCode.InternalServerError 
            member this.Returns201() =
                WebOperationContext.Current.OutgoingResponse.StatusCode <- 
                    System.Net.HttpStatusCode.Created 
    
    let addr = "http://localhost/MyService"
    let host = new WebServiceHost(typeof<MyService>, new Uri(addr))
    host.AddServiceEndpoint(typeof<IMyContract>, new WebHttpBinding(), "") |> ignore
    host.Open()
    
    open System.Net
    
    let url500 = "http://localhost/MyService/Returns500"
    let url201 = "http://localhost/MyService/Returns201"
    let async_value (url:string) = 
        async {  
            let req = WebRequest.Create(url)  
            let! rsp = req.AsyncGetResponse()  
            return (rsp :?> HttpWebResponse).StatusCode
        }
    let status = Async.RunSynchronously(async_value url201)
    printfn "%A" status
    try
        let status = Async.RunSynchronously(async_value url500)
        printfn "%A" status
    with e ->
        printfn "%s" (e.ToString())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I have a bunch of posts stored in text files formatted in yaml/textile (from
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm making a simple page using Google Maps API 3. My first. One marker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.