Anonymous
Anonymous

Reputation: 1979

C# Web Service and Global Variables

I'm having a problem getting my global variables to work on my client application.

In the web service, I have the following code:

public class MyWebService: System.Web.Services.WebService
{
    public static string test = String.Empty;
    ....

On my client side I have this code:

MyService.MyWebService client = new MyService.MyWebService()
{
    client.test="test";
};

On the client side I'm receiving

"MyWebService does not contain a definition for test...etc";

Can you use global variables within a web service? Any help would be appreciated.

Thanks!

Upvotes: 2

Views: 6498

Answers (2)

Thorsten Dittmar
Thorsten Dittmar

Reputation: 56697

Even though it may look like you're actually using classes when invoking web services, you're not. Web services do not know the concept of variables. All you can do is invoke methods.

Upvotes: 2

Ondrej Svejdar
Ondrej Svejdar

Reputation: 22054

You'll have to expose getter (and or setter) in webservice in order to be visible for client. i.e:

public class MyWebService: System.Web.Services.WebService
{
    public static string test = String.Empty;
    public string GetTest() {
      return test;
    }
    public void SetTest(string test) {
      MyWebService.test = test;
    }
}

Also read some topic on thread-safety, if you're planning to have more clients simultaneously.

Upvotes: 3

Related Questions