Cannot convert IAsyncResult to AsyncResult when using a service refrence
Posted
by Scott Chamberlain
on Stack Overflow
See other posts from Stack Overflow
or by Scott Chamberlain
Published on 2010-03-12T20:23:50Z
Indexed on
2010/03/12
20:27 UTC
Read the original article
Hit count: 575
I have a WCF service running, I added a reference to the service by using Add Service Reference in the solution explorer, and I checked the box for create asynchronous operations.
My call works fine, I have a two way channel that reports back some events from the server and I am receiving the events. However, when the asynchronous task finishes in my callback handeler I get the error Unable to cast object of type 'SendAsyncResult' to type 'System.Runtime.Remoting.Messaging.AsyncResult'.
Code that calls the method.
DatabaseManagement.DatabaseManagementClient d = new DatabaseManagement.DatabaseManagementClient(new InstanceContext(new DatabaseManagementCallback()));
d.Open();
d.BeginCreateDatabase("", "PreConfSA", "_test", new AsyncCallback(BeginCreateDatabaseCallback), null);
The Async callback
static void BeginCreateDatabaseCallback(IAsyncResult ar)
{
AsyncResult result = (AsyncResult)ar; //Execption happens here
DatabaseManagement.DatabaseManagementClient caller = (DatabaseManagement.DatabaseManagementClient)result.AsyncDelegate;
Console.WriteLine(caller.EndCreateDatabase(ar));
//Do more stuff here
}
Execption Details
System.InvalidCastException was unhandled by user code
Message=Unable to cast object of type 'SendAsyncResult' to type 'System.Runtime.Remoting.Messaging.AsyncResult'.
Source=Sandbox Console
StackTrace:
at Sandbox_Console.Program.BeginCreateDatabaseCallback(IAsyncResult ar) in E:\Visual Studio 2010\Projects\Sandbox Console\Program.cs:line 26
at System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously)
InnerException:
I don't really need the result from the EndCreateDatabase but everywhere I read it says that you must call EndYouFunctionHere() or bad things happen.
Any recomendations?
© Stack Overflow or respective owner