在 ASP.NET 代码后面使用 Web 服务的最佳方式
我试图在页面加载时将数据源绑定到中继器,例如绑定到 Web 服务(来自不同网站的 .asmx)。 Web 服务从 sql 调用返回一个 DataSet。 这样做的最佳方法是什么?
I'm trying to bind a datasource to a repeater, for instance, to a web service (.asmx from a different website) on page load. The webservice returns a DataSet from an sql call. What is the best way to go about doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因为您正在调用另一个网站,所以您必须解决两个问题(特别是如果此网络服务位于其他人的网站上或通过公共互联网)。 首先,从其他网站检索数据可能会出现延迟。 其次,其他网站可能会超时。
您至少应该考虑异步页面请求。 正如这篇 MSDN 文章所述:
但最好的解决方案可能是使用 AJAX。加载页面,然后发出 ajax 请求来填充转发器。这样,您可以在等待 Web 服务时看到漂亮的“旋转”图形或其他事情。
Because you're calling another website, you have to contend with two issues (especially if this web service is on somebody else's website or over the public internet). First, there might be a delay to retrieve the data from the other website. Second, the other website might timeout.
At a minimum you should consider an asychronous page request. As this MSDN article states:
But the best solution is probably to use AJAX. Load the page then make an ajax request to fill the repeater. That way you can have the nice "spinning" graphic or something else happening while you are waiting on the webservice.
调用网络服务,获取结果,并将其绑定到您的中继器。
如果可以的话,您还可以尝试将信息缓存一段时间,以帮助提高整体性能。
Call the webservice, take the result, and bind it to your repeater.
If you can, you might also try to cache the information for a time on your side, if possible to help with overall performance.