我知道这个问题之前已经解决了,但我有服务返回这样的字符串。
[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");
问题是当我添加参考时,我无法获得 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 方法,为什么我会收到上述错误?
谢谢你的时间。