Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 663221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:27:57+00:00 2026-05-13T23:27:57+00:00

I have a WCF service running, I added a reference to the service by

  • 0

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));
    DatabaseManagement.AccountInfo ai = new DatabaseManagement.AccountInfo();
    //set up ai here
    Console.WriteLine(caller.UpdateInfo("", "_test", ai));
}

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?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:27:57+00:00Added an answer on May 13, 2026 at 11:27 pm

    The EndXxx methods generated for a service reference have the signature:

    EndXxx(IAsyncResult result);
    

    (At least they do in my environment — are you seeing something different?)

    So you don’t actually need to perform the cast in order to call the EndXxx method.

    However, in that case you do need some way to get the service reference (client instance) into the callback method, because you can’t get at it using AsyncResult.AsyncDelegate. You can do this either by storing the proxy object in a member variable instead of a local variable, or pass it to the BeginXxx method as the asyncState:

    d.BeginCreateDatabase("", "PreConfSA", "_test",
      new AsyncCallback(BeginCreateDatabaseCallback),
      d);  // passing d as asyncState instead of null
    

    Then retrieve it from the IAsyncResult.AsyncState in the callback:

    DatabaseManagement.DatabaseManagementClient caller =
      (DatabaseManagement.DatabaseManagementClient)ar.AsyncState;
    

    This removes any assumptions about the specific implementation of IAsyncResult.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a ASP.NET application running and i have added a WCF Rest service
I have a WCF service running on Windows 2008 R2 64 bit, using IIS
I have a WCF service running on my machine, which get lauched while I
I have a WCF service running inside a windows service on a remote machine.
I have a netTcp WCF service running in a windows service on a remote
I have a very simple WCF service running that has a single method that
I have a WCF service method that's running in a worker thread I spin
I have a WCF service (the same one) running on multiple servers, and I'd
I have a WCF service which works on my dev machine running IIS 7,
We have an application that has a WCF service (*.svc) running on IIS7 and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.