简体   繁体   English

ASP.NET:为什么我不能在一个页面中两次调用Web服务?

[英]ASP.NET: Why can't I call a web-service twice in one page?

I built a web-application which calls a web-service twice in the application's log-in page - first, on Page_Load, and the second time is after a button click. 我构建了一个Web应用程序,该应用程序在应用程序的登录页面中两次调用Web服务-首先是在Page_Load上,第二次是在单击按钮之后。 When debugging, everything goes well, but after publishing the web-application and trying it - I cannot make the two calls for the web-service (each call is invoking a different function in the same web-service). 调试时,一切正常,但是发布了Web应用程序并对其进行了尝试之后-我无法对Web服务进行两次调用(每个调用都在同一Web服务中调用不同的功能)。

If I call it once (say, in the Page_Load) its OK, but once I get to the button click event, the page just seems to be loading but actually doing nothing (loading to infinity). 如果我一次调用它(例如,在Page_Load中)就可以了,但是一旦获得按钮click事件,该页面似乎只是在加载,但实际上什么也没做(加载到无穷大)。

When I disabled the web-service call in Page_Load, the web-service call after the button click worked well, and if I switched between them (disabled the call in button click and enabled the call in Page_Load) the enabled one worked OK. 当我禁用Page_Load中的Web服务调用时,单击按钮后的Web服务调用运行良好,并且如果我在它们之间切换(禁用了按钮单击中的调用并启用了Page_Load中的调用),则已启用的服务正常。

How come this is happening? 怎么会这样呢? What did I do wrong? 我做错了什么? Could it be related to the fact that the location where I published my web-application has some URL-rewriting rules? 可能与我发布Web应用程序的位置具有一些URL重写规则这一事实有关吗?


I don't use (!isPostBack) - I did try to put both calls after the button click event though, and still had the same problem. 我不使用(!isPostBack)-我确实尝试将两个调用都放在按钮单击事件之后,但仍然存在相同的问题。

Relevant parts of the code: 代码的相关部分:

protected void Page_Load(object sender, EventArgs e)
{
    MyService.Functions service = new MyService.Functions();
    string str = service.DigestURL(Request.RawUrl.ToString());
    ...
}


public void submitButton_Click(object sender, ImageClickEventArgs e)
{
    MyService.Functions service = new MyService.Functions();
    string str = service.CommitLogIn(usernameText.Text, passwordText.Text);
    ...
}

Can you show some code segment? 您可以显示一些代码段吗? Have you used if (!isPostBack) in the Page_Load for calling the webservice? 您是否已使用Page_Load中的if (!isPostBack)来调用Web服务? The Page_Load fires when the button is clicked. 单击该按钮时将触发Page_Load There might be an issue in that. 可能有一个问题。

If you are using WCF, make sure you close the client. 如果使用的是WCF,请确保关闭客户端。 I had similar behaviour before when I did not close it. 在没有关闭它之前,我有类似的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM