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

  • SEARCH
  • Home
  • 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 6474617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:36:30+00:00 2026-05-25T06:36:30+00:00

I’m currently updating a client application that makes use of a WCF web service

  • 0

I’m currently updating a client application that makes use of a WCF web service from synchronous to asynchronous calls. The main server and the client are on the same local network, but it is too unreliable for the application to hang while it waits for a response.

The application makes use of 4 identical endpoints across 2 servers (so if an instance has crashed or a server is offline, there should still be something to call).

The client has a layer responsible for making calls to the web service. My initial synchronous design was for the the active endpoint to be called and if an exception was thrown we would then move to the next endpoint and recursively call the same method. This would be done until all endpoints are exhausted.

I’ve now made the modifications to make this async but there is one issue. The parameters are lost once we are in the callback. So when it it time to call the Begin method again recursively, the parameters are not accessible to be passed in again.

What would be the best way to pass parameters from the Begin method to the callback method? Are they stored anywhere in the client object? Can it be done through the event or should I store them at the class level?

    public delegate void GetUserInfoCompletedEventHandler(UserInfo e);
    public static event GetUserInfoCompletedEventHandler GetUserInfoCompleted;
    public delegate void GetUserInfoFaultedEventHandler(string errorMessage);
    public static event GetUserInfoFaultedEventHandler GetUserInfoFaulted;


        public static void BeginGetUserInfo(string fobID)
    {
        MyClient client = new MyClient(availableEndpoints[activeEndpointIndex].Name);
        client.GetUserInfoCompleted += new EventHandler<GetUserInfoCompletedEventArgs>(client_GetUserInfoCompleted);
        client.GetUserInfoAsync(fobID);
    }


static void client_GetUserInfoCompleted(object sender, GetUserInfoCompletedEventArgs e)
    {
        // Get the instance of the client
       MyClient client = (MyClient)sender;      

        if (null == e.Error)
        {
            // Close the client instance if there was no error
            try { client.Close(); }
            catch { }

            if ((null != GetUserInfoCompleted) && (null != e.Result))
            {
                // Report as successful and raise the event
                ServiceActionSuccessful();
                GetUserInfoCompleted(e.Result);
            }
        }
        else
        {
            // Abort the client as there was an error
            try { client.Abort(); }
            catch { }

            if (e.Error is FaultException<WebServiceError>)
            {
                FaultException<WebServiceError> fault = (FaultException<WebServiceError>)e.Error;

                if (null != GetUserInfoFaulted)
                {
                    // A fault occurred in the web service
                    GetUserInfoFaulted(fault.Detail.ErrorMessage);
                }
            }
            else
            {
                // Assume this was problem in connection so test if there any more endpoints to attempt
                bool isNextEndpointAvaialble = ServiceActionFailure();

                if (isNextEndpointAvaialble)
                {
                    // If there are more endpoints to try, call the method to run again
                    BeginGetUserInfo(); // Need parameters here
                }
                else
                {
                    if (null != GetUserInfoFaulted)
                    {
                        // No more endpoints to try
                        GetUserInfoFaulted(Errors.GetUserFriendlyMessage(e.Error));
                    }
                }
            }
        }
    }
  • 1 1 Answer
  • 0 Views
  • 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-25T06:36:31+00:00Added an answer on May 25, 2026 at 6:36 am

    If MyClient is a generated class, there should be a second function called

    MyClient.GetUserInfoAsync(string fobID, object userState);
    

    The content of the userState argument is passed dirctly to the GetUserInfoCompletedEventArgs.UserState property in the eventargs received by client_GetUserInfoCompleted.

    So you could do something like this:

    public static void BeginGetUserInfo(string fobID)
    {
        MyClient client = new MyClient(availableEndpoints[activeEndpointIndex].Name);
        client.GetUserInfoCompleted += new EventHandler<GetUserInfoCompletedEventArgs>(client_GetUserInfoCompleted);
        client.GetUserInfoAsync(fobID, fobID);
    }
    
    static void client_GetUserInfoCompleted(object sender, GetUserInfoCompletedEventArgs e)
    {
        string fobID = e.UserState as string;
        // handle the event here...
    }
    

    Another alternative is to use a lambda for handling the event:

    public static void BeginGetUserInfo(string fobID)
    {
        MyClient client = new MyClient(availableEndpoints[activeEndpointIndex].Name);
        client.GetUserInfoCompleted += (sender, args) => client_GetUserInfoCompleted(sender, args, fobID);
        client.GetUserInfoAsync(fobID);
    }
    
    static void client_GetUserInfoCompleted(object sender, GetUserInfoCompletedEventArgs e, string fobID)
    {
        // access the additional parameter fobID here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.