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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:23:51+00:00 2026-05-19T03:23:51+00:00

I have a Web Service project and a WPF project (which serves as a

  • 0

I have a Web Service project and a WPF project (which serves as a client) in my solution.

The class representing the web service is quite simple and looks like this:

public class CardsGameService : System.Web.Services.WebService
{
    private Card magicCard;

    // Acts as a getter for magicCard field
    [WebMethod]
    public Card GetMagicCard()
    {
        return magicCard;
    }

    // Creates some random cards and sets the magicCard field
    [WebMethod]
    public Card[] GetNewCardSet()
    {
        Card[] cardSet = new Card[4];

        for (int i = 0; i < 4; i++)
        {
            cardSet[i] = GetRandomCard();
        }

        Random random = new Random();
        int index = random.Next(0, 3);

        // This field does get its value and 
        // is not null when this method is executed
        magicCard = cardSet[index];

        return cardSet;
    }
}

In my client WPF code-behind class, I am instantiating CardsGameServiceSoapClient service and calling the GetNewCardSet() web method which returns the set of cards.

Here’s the problem:
If I want to call the web method GetMagicCard() later on, it always returns null. Why? I am instantiating CardsGameServiceSoapClient service only once and this object is alive for as long as I run my client application.

  • 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-19T03:23:52+00:00Added an answer on May 19, 2026 at 3:23 am

    Because the WebService instance is created and discarded on a per-call basis. If you want to share state between multiple web service calls, then use a static field. But beware that you need to worry about the same kind of issues you would when dealing with any other multi-threaded code. Two calls could be in progress at the same time so you need to use locks where appropriate.

    Also worth mentioning is that IIS can and will terminate your application domain for any reason at any time so you shouldn’t rely on the fact that the field will hang around indefinitely. If you need it to persist then use a database or other persistent storage.

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

Sidebar

Related Questions

I have a simple task. I have an existing project with a web service
I have an WPF-MVVM solution with multiple service projects interconnected by a web of
I have a web service project and simple test application. I can debug the
I have a web service project that contains 3 classes: 1 Abstract public class
I have an ASP.NET (.asmx) Web Service project that has a method like: public
I have a Windows forms project and a Web Service project in my solution,
I have an aspx web form in a WCF service project that gives a
At present I have a TestNG project that calls a JBoss RESTEasy web service.
Interesting one here. I have an ASP.NET 1.1 project that contains a web service
I have a webservice project (old asmx technology) in which I have a class

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.