我正在使用ASP.NET應用程序和Web服務,出於某種原因Web服務方法之一被跳過。我相信這是一個相當簡單的問題,但是讓我陷入了一天的困境。我將方法調用放在錯誤的方法中,我會假設OnPreRender會在頁面加載之前處理所有內容。我相當確信問題出現在這個區域,如果在實例化表單時將表單對象的ImageLoc設置爲URL,那麼它會很好地加載到ASP.NET頁面中。跳過了Web服務方法?
我不認爲我遺漏了任何相關代碼,但如果您需要查看其他內容,請告訴我。表單對象只是get/set的幾個屬性,所以我把它放在了外面。另外請注意,字符串參數將更改爲其他內容,我只是試圖建立基礎工作。
.aspx.cs:
localhost.MobileFormServices wsMobile = new localhost.MobileFormServices();
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
//Call the web service to pass image URL
wsMobile.NewForm("parameters");
FormImage.ImageUrl = wsMobile.FormProperties().ImageLoc;
}
Web服務方法:
//new form object instance
private FormLibrary.Form form = new FormLibrary.Form();
//adds the image location to the form object
[WebMethod]
public void NewForm(String parameters)
{
form.ImageLoc = "http://www.prelovac.com/vladimir/wp-content/uploads/2008/03/example.jpg"; //breakpoint here, never hit
}
[WebMethod]
public FormLibrary.Form FormProperties()
{
return this.form;
}
這對我有意義,但你會如何建議解決這個問題? – turbo
我給了它一些想法,將一個表單對象傳遞給asp.net應用程序,使用/修改它,然後通過Web服務傳遞回來解決它?我現在要嘗試一下。 – turbo
您可以將FormLibrary.Form作爲靜態存儲,但這會在共享相同表單的所有頁面中結束,這可能很糟糕,但取決於每個項目。其他方法是將其存儲在Session或某些外部存儲庫(如數據庫)中。或者如果你真的在你的應用中使用兩個電話,也許你應該做到這一點?在這個例子中,第二次調用沒有意義。第一次電話應該返回你所需要的。如果你覺得這個答案有用,請upvote :) –