我正在使用带有Web服务的ASP.NET应用程序,并且出于某种原因,会跳过其中一个Web服务方法。我确定这是一个相当简单的问题,但它让我难倒了一天多。我用错误的方法调用方法调用,我认为OnPreRender会在页面加载之前处理所有内容。我相信这个问题就在这个领域,如果我在实例化时将表单对象的ImageLoc设置为一个URL,那么它在ASP.NET页面加载就好了。
我认为我没有遗漏任何相关代码,但如果您需要查看其他任何内容,请告知我们。表单对象只是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;
}
网络服务方法:
//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;
}
答案 0 :(得分:1)
您确定没有调用Web服务吗?电话
FormImage.ImageUrl = wsMobile.FormProperties().ImageLoc;
虽然在页面上使用相同的对象实例,但在Web服务端调用的方法与方法
完全不同 wsMobile.NewForm("parameters");
被召唤。因为那个
private FormLibrary.Form form = new FormLibrary.Form();
每次通过Web服务调用都会调用。
在每个Web服务调用上,都会创建处理该调用的Web服务的新实例。 所以在你的例子中。
wsMobile.NewForm(“parameters”) - 在创建处理此调用的实例时创建新的FormLibrary.Form。
在此调用中您设置了form.ImageLoc - 但此表单是该实例的本地形式
FormImage.ImageUrl = wsMobile.FormProperties()。ImageLoc; - 再次创建新的FormLibrary.Form以处理此调用
您返回新创建的FormLibrary.Form的ImageLoc。不是你之前设定的。
答案 1 :(得分:0)
您可以尝试使用OnPreRenderComplete事件而不是OnPreRender。
答案 2 :(得分:0)
有时调试器会感到困惑。试试这个(并重建所有):
[WebMethod]
public void NewForm(String parameters)
{
System.Diagnostics.Debugger.Break();
form.ImageLoc = "http://www.prelovac.com/vladimir/wp-content/uploads/2008/03/example.jpg"; //breakpoint here, never hit
}
答案 3 :(得分:0)
尝试将OnPreRender()代码移动到OnInit()。