有什么方法可以使用jQuery调用f#库,而不必将其包装到Web服务方法中?
Is there any way to make a call to an f# library using jQuery without having to wrap it into a web service method?
推荐答案如注释中所述,您可以将F#转换为JavaScript.这实际上是可行的,因为它可以使用引号(F#代码的高级表示形式).有两个项目可以做到这一点.一个是相当复杂的名为WebSharper的商业项目(也具有其他功能),另一个是开源项目FSharp.Javascript .
As mentioned in comments, you could translate F# to JavaScript. This is actually pretty doable, because it can use quotations (a high-level representation of F# code). There are two projects that do this. One is a rather sophisticated commercial project named WebSharper (which has other features too) and the other one is open source project FSharp.Javascript.
如果要避免使用Web服务,还可以编写一个简单的HTTP服务器.这将是一个可以在服务器上运行的独立应用程序,它将直接处理请求.我在最近的在伦敦的谈话中使用HttpListener类进行了此操作.您可以在此处找到示例.
If you want to avoid web services, you can also write a simple HTTP server. This would be a standalone application that you can run on your server and it will directly handle requests. I did that using HttpListener class in a recent talk in London. You can find the sample here.
肯定还有其他方法-如果您在ASP.NET应用程序中工作,则可以使用HttpHandler或用F#编写的页面,该页面将直接处理请求.将主要前端作为C#项目可能更容易,但是您可以在F#中编写页面/处理程序,然后在C#中引用或继承它(例如,使用ASP.NET MVC在这里).
There are definitely other ways - if you're working in ASP.NET application, then you can use HttpHandler or a page written in F# that will just handle the request directly. It is probably easier to have the main front-end as a C# project, but you can write the page/handler in F# and just reference it or inherit from it in C# (example using ASP.NET MVC is here).
更多推荐
jQuery Ajax调用F#吗?
发布评论