是否有某种方式来处理异步/等待ASMX服务的背后? [英] Is there some way to handle async/await behind an ASMX service?

查看:156
本文介绍了是否有某种方式来处理异步/等待ASMX服务的背后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我服役JSON WCF的REST API和ASMX Web服务的Web应用程序。该应用程序已经有好几年了。它是基于ASP.NET 2.0,但几年前升级到.NET 4.0的,我刚刚升级到.NET 4.5,以便能够使用新的异步架构。

I have a web app serving a WCF REST API for JSON and an ASMX web service. The application has been around for a few years. It's based on ASP.NET 2.0, but upgraded to .NET 4.0 a couple of years ago, and I just upgraded to .NET 4.5 to be able to use the new async framework.

应用的背后,是一些传统服务,我意识到,有一种通过将异步提高性能有很大的潜力。我已经实现异步通过应用程序所有的方式,一切通过WCF REST API可以正常使用。

Behind the application are some legacy services, and I realized that there is a big potential for increasing the performance by going async. I have implemented async all the way through the application, and everything is working perfectly through the WCF REST API.

太晚了,我发现了ASMX API失败,我想这样的方法:

Too late I discovered that the ASMX API fails, I wanted methods like this:

[WebMethod(Description = "Takes an internal trip ID as parameter.")]
async public Task<Trip> GetTrip(int tripid)
{
    var t = await Trip.GetTrip(tripid);
    return t;
}

然后我了解到,异步/伺机不支持ASMX不惜一切,每个人都建议迁移到WCF。我不是太快乐这一点。该ASMX(实际上他们三个)塞满了不同的方法,还有我们要不断的从旧的API服务API消费者的负荷。

I then learned that async/await isn't supported in ASMX at all, and everybody advises to migrate to WCF. I am not too joyful about this. The ASMX (actually three of them) are stuffed with different methods, and there are loads of API consumers that we want to keep serving from the old API.

但是,我们需要更高的性能!有谁知道一个解决办法,所以我可以继续使用异步/等待ASMX落后,但像以前那样暴露ASMX?

But we need the increased performance! Does anybody know about a workaround so I can keep using async/await behind the ASMX, but expose the ASMX as before?

推荐答案

也许可以做到这一点,但是这将是一个有点尴尬。 ASMX支持APM式异步方法的,你可以的convert TAP到APM (但是,请注意,该网页上的MSDN例如不正确地传播例外)。

It may be possible to do this, but it would be a bit awkward. ASMX supports APM-style asynchronous methods, and you can convert TAP to APM (however, note that the MSDN example on that page does not propagate exceptions correctly).

我有显示如何包装TAP实现在我的博客上的例子APM (与保持正确的异常类型,但失去了堆栈异常传播;见<$c$c>ExceptionDispatchInfo为全面正确的异常传播)。我用了一会儿,当WCF只支持APM。一个非常类似的方法应该适用于ASMX。

I have an example on my blog that shows how to wrap TAP implementations in APM (with exception propagation that keeps the correct exception type but loses the stack; see ExceptionDispatchInfo for fully correct exception propagation). I used this for a while when WCF only supported APM. A very similar approach should work for ASMX.

不过,请注意,您<一个href=\"http://blogs.msdn.com/b/webdev/archive/2012/11/19/all-about-httpruntime-targetframework.aspx\">have目标4.5(即 httpRuntime.targetFramework )的异步 / 等待按预期工作。

However, note that you will have to target 4.5 (i.e., httpRuntime.targetFramework) for async/await to work as expected.

这篇关于是否有某种方式来处理异步/等待ASMX服务的背后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆