我知道这已被解决之前,但我有服务,返回一个像这样的字符串。异步web服务调用。无(Begin ...)方法可用!
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class MyService : System.Web.Services.WebService
{
[WebMethod]
public string Hello()
{
System.Threading.Thread.Sleep(10000);
return "Hello User";
}
}
我读过很多例子是说我需要调用的方法是这样的:
MyService my = new MyService();
AsyncCallback async = new AsyncCallback(callback);
my.BeginHello();
Console.WriteLine("Called webservice");
的事情是,当我说我参考拿到coudn't的BeginHello方法。我看到的只是HelloAsync。所以我在我的控制台应用程序中使用它。
MyService my = new MyService();
AsyncCallback async = new AsyncCallback(callback);
my.HelloAsync();
Console.WriteLine("Called webservice");
和定义如下
private void callback(IAsyncResult res)
{
Console.Write("Webservice finished executing.");
}
私人回调方法,在此过程中,我得到这样的错误:
的对象引用需要 非静态字段,方法或 属性 'AsyncWebserviceCall.Program.callback(System.IAsyncResult)
为什么我不能得到BeginHello方法&为什么我得到如上的错误?
谢谢你的时间。
请向我们展示整个类(回调和调用web服务的方法) – jgauffin 2010-10-14 11:06:59