0
J'essaie de faire un simple appel asynchrone avec WCF, mais la fonction de rappel n'est jamais exécutée. Quelqu'un peut-il me dire ce qui ne va pas avec le code?La fonction de rappel n'est pas exécutée dans un appel asynchrone
J'utilise Visual Studio 2008 avec .Net 3.5
Code service
[ServiceContract]
public interface IService1
{
[OperationContract(AsyncPattern = true) ]
IAsyncResult BeginGetData(string value, AsyncCallback callback, object state);
string EndGetData(IAsyncResult result);
}
public class Service1 : IService1
{
#region IService1 Members
public IAsyncResult BeginGetData(string value, AsyncCallback callback, object state)
{
return new CompletedAsyncResult<string>(value, state);
}
public string EndGetData(IAsyncResult r)
{
CompletedAsyncResult<string> result = r as CompletedAsyncResult<string>;
return result.Data;
}
#endregion
}
code côté client
class Program
{
static void Main(string[] args)
{
Service1Client client = new Service1Client();
Console.WriteLine("Start async call");
IAsyncResult result = client.BeginGetData("abc", callback, null);
Console.ReadLine();
}
static void callback(IAsyncResult result)
{
string a = "in callback";
Console.WriteLine(a);
}
}
+1 Oui, vous manque la partie très basique. Si vous ne spécifiez pas le rappel dans BeginInvoke, comment sera-t-il appelé? D'autres liens pour votre référence http://stackoverflow.com/questions/1047662/what-is-asynccallback/1047677#1047677 http://msdn.microsoft.com/en-us/library/2e08f6yc.aspx –