在 ASP.NET 代码后面使用 Web 服务的最佳方式

发布于 2024-07-08 09:04:13 字数 98 浏览 4 评论 0原文

我试图在页面加载时将数据源绑定到中继器,例如绑定到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寻梦旅人 2024-07-15 09:04:13

因为您正在调用另一个网站,所以您必须解决两个问题(特别是如果此网络服务位于其他人的网站上或通过公共互联网)。 首先,从其他网站检索数据可能会出现延迟。 其次,其他网站可能会超时。

您至少应该考虑异步页面请求。 正如这篇 MSDN 文章所述:

如果同步请求变成I/O
绑定——例如,如果它调用
远程 Web 服务或查询
远程数据库并等待调用
回来——然后线程被分配
请求被卡住,什么都不做
直到电话返回。 这阻碍了
由于线程池的可扩展性
线程数量有限
可用的。 如果所有请求处理
线程被阻塞等待 I/O
要完成的操作,附加
请求排队等待
线程是免费的。 最好,
吞吐量下降,因为请求
等待更长的时间来处理。 最坏的情况是,
队列已满并且 ASP.NET 失败
后续请求 503“服务器
不可用”错误。

但最好的解决方案可能是使用 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:

If a synchronous request becomes I/O
bound—for example, if it calls out to
a remote Web service or queries a
remote database and waits for the call
to come back—then the thread assigned
to the request is stuck doing nothing
until the call returns. That impedes
scalability because the thread pool
has a finite number of threads
available. If all request-processing
threads are blocked waiting for I/O
operations to complete, additional
requests get queued up waiting for
threads to be free. At best,
throughput decreases because requests
wait longer to be processed. At worst,
the queue fills up and ASP.NET fails
subsequent requests with 503 "Server
Unavailable" errors.

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.

机场等船 2024-07-15 09:04:13

调用网络服务,获取结果,并将其绑定到您的中继器。

如果可以的话,您还可以尝试将信息缓存一段时间,以帮助提高整体性能。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文