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 7753083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:57:50+00:00 2026-06-01T11:57:50+00:00

Just getting my head around WCF, so forgive me for the inelegant coding. The

  • 0

Just getting my head around WCF, so forgive me for the inelegant coding.
The issue I’m having is I seem to be submitting data twice to my service (see screenshot), even though (I think) I’m only doing it once.
Could someone please let me know what I might be doing wrong? Or even just suggest a better way to do it if I’m doing it inefficiently.

Code follows:

public void EndOfLevel()
    {
        GlobalVariable.TotalQuestionsAsked = 10;
        GlobalVariable.CorrectDecimal = GlobalVariable.Correct / GlobalVariable.TotalQuestionsAsked;

        //Show loading screen
        UploadingScreen.Visibility = Visibility.Visible;
        //Submit this levels results.

        Service1Client client = null;
        client = new Service1Client();

            //Gather the results and details
            Result thislevel = new Result();
            thislevel.Datetime = DateTime.Now;
            thislevel.result = GlobalVariable.CorrectDecimal;
            thislevel.TimesTable = GlobalVariable.NeedsHelpWith;

            //submit them
            try
            {
                client.SubmitResultAsync(thislevel);
            }
            catch
            {
                MessageBox.Show("Error uploading data");
            }
            finally
            {
                client.Close();
                Results r3 = new Results();
                this.NavigationService.Navigate(r3);
            }



    }

WCF Test Client:

Screenshot of the results

Cheers,
Nick

  • 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-06-01T11:57:51+00:00Added an answer on June 1, 2026 at 11:57 am

    If I may, here’s a pattern for managing our asynchronous calls between our WPF applications and our WCF Services.

    In this section we have a public accessor to our service client that ensures that the connection to the client is open prior to calling a service method:

    public static MyServiceClient Client
    {
        get
        {
            return GetMyServiceClient();
        }
    }
    private static MyServiceClient client;
    
    private static MyService.MyServiceClient GetMyServiceClient()
    {
        VerifyClientConnection();
    
        return client;
    }
    
    private static void VerifyClientConnection()
    {
        if (client == null || client.State == System.ServiceModel.CommunicationState.Closed)
        {
            client = new MyService.MyServiceClient();
        }
    }
    

    And in this section is an example of our asynchronous call and callback pattern (this example shows the delegate and callback we’re using for passing exception data to our service):

    public delegate void LogExceptionCompletedEvent();
    public static LogExceptionCompletedEvent LogExceptionCompleted;
    
    public static void LogExceptionAsync(SilverlightException exception)
    {
        string json = JsonConvert.SerializeObject(exception);
    
        Client.LogExceptionCompleted -= client_LogExceptionCompleted;
        Client.LogExceptionCompleted += client_LogExceptionCompleted;
        Client.LogExceptionAsync(json);
    }
    
    private static void client_LogExceptionCompleted(object sender, AsyncCompletedEventArgs e)
    {
        if (LogExceptionCompleted != null)
        {
            LogExceptionCompleted();
        }
    }
    

    In this example, a view model could attach an event handler to the LogExceptionCompleted delegate and in turn receive the result of the callback when it returns from the service.

    We basically repeat this pattern for the asynchronous WCF service calls we need to make from our application and it keeps them very organized as well as unit testable.

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

Sidebar

Related Questions

I'm having a hard time getting my head around this, and Google just isn't
Arghhh! I'm getting so frustrated trying to get my head around this WCF service.
Just getting my head around Linq and having lots of fun! Can any one
Just getting my head around Ruby metaprogramming. The mixin/modules always manage to confuse me.
I'm just getting my head around java (and OOP for that matter), the only
I'm just getting my head around insert statements today after getting sick of cheating
I'm just getting into JavaScript and I'm trying to wrap my head around prototypal
I'm having a right barney getting my head around how everything fits together using
I just started getting my head around Java itself and Java Swing and I
I'm having a hard time getting my head around custom delegation - I would

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.