1

有人可以告诉我在 F# 中编写异步 http 处理程序时使用的好模式吗?

我必须实现IHttpAsyncHandler并且该接口需要一个BeginProcessRequestand EndProcessRequest

我要回来Async.StartTask吗?我该如何处理state:objAsyncCallback

4

2 回答 2

3

突然想到:使用异步工作流实现处理程序,然后使用 Async.AsBeginEnd 公开它

open System
open System.Web

type HttpAsyncHandler() = 

    let processRequestAsync (context : HttpContext) = async {
        // TODO: implement
        return()
        }

    let beginAction, endAction, _ = Async.AsBeginEnd(processRequestAsync)

    interface IHttpAsyncHandler with
        member this.BeginProcessRequest(context, callback, extraData) = beginAction(context, callback, extraData)
        member this.EndProcessRequest(iar) = endAction (iar)
        // other members omitted
于 2012-04-04T18:02:13.053 回答
1

你到底想做什么?如果可以,您可能需要HttpMessageHandler考虑System.Net.Http. 您只需覆盖

protected abstract Task<HttpResponseMessage> SendAsync(
    HttpRequestMessage request,
    CancellationToken cancellationToken);

method, which is easy with an async { ... } |> Async.StartAsTask. You also get better access to the various attributes of HTTP through static typing. Various subclasses allow you to run either through ASP.NET, WCF (self-host), or even third-part platforms like OWIN.

于 2012-04-05T04:22:10.150 回答