473,395 Members | 1,937 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

webservices: simple question, accessing webservice members

Hi, (new to webservices here)

Is it possible to access a class instance variable defined in a webservice?
I want to access this variable, in addition to the data being returned by
the [webmethod].

so let's say I have the following webservice class:
public class Service1 : System.Web.Services.WebService
{

public string hello2;

public ModelServices()
{
InitializeComponent();
}

[WebMethod]
public string sayHello()
{
hello2 = "another hello to you!"
return "hello there";
}
}
................................

So when I consume this webservice, I want to be able to call the sayHello()
method, and have access to the hello2 variable after having called sayHello
() and thus expecting the "hello2" variable to contain the "another hello
to you!" value:
remoteWS.Service1 ws = new remoteWS.Service1();
string hello1 = ws.sayHello();
string hello2 = ws.hello2;

Is this possible, and how do I go about doing it? thanks!
Nov 21 '05 #1
5 1320
I don't think you can access a public member of
System.Web.Services.WebService class from a client side. I would either
stored the value in database or use Session in the web service.

Good luck!

============================
Hayato Iriumi (hi*****@hotmail.com)
Blog: http://www.vbaspcoder.com
"hellrazor" <jo***@another-world.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
Hi, (new to webservices here)

Is it possible to access a class instance variable defined in a webservice? I want to access this variable, in addition to the data being returned by
the [webmethod].

so let's say I have the following webservice class:
public class Service1 : System.Web.Services.WebService
{

public string hello2;

public ModelServices()
{
InitializeComponent();
}

[WebMethod]
public string sayHello()
{
hello2 = "another hello to you!"
return "hello there";
}
}
...............................

So when I consume this webservice, I want to be able to call the sayHello() method, and have access to the hello2 variable after having called sayHello () and thus expecting the "hello2" variable to contain the "another hello
to you!" value:
remoteWS.Service1 ws = new remoteWS.Service1();
string hello1 = ws.sayHello();
string hello2 = ws.hello2;

Is this possible, and how do I go about doing it? thanks!

Nov 21 '05 #2
you can either add another webmethod to return the new value (which is
chatty and inefficient) or you can return a class that contains both values.

For example:

public class SharedClass
{
string MyHello1;
string MyHello2;
}

public class Service1: System.Web.Services.WebService
{
// put initializer here... ommitted for brevity
[WebMethod]
public SharedClass SayHello()
{
SharedClass sc = new SharedClass();
sc.MyHello1 = "Hello There";
sc.MyHello2 = "And Again";
}
}

public class WebClient
{
public void MyClient()
{
Service1 mywebservice;
mywebservice.SayHello();
Console.WriteLine("{0}", mywebservice.MyHello1);
Console.WriteLine("{0}", mywebservice.MyHello2);
}
}

((Caveat: this code is from the top of my head... it has not been
compiled... please excuse typos))

Hope this helps,
--- Nick

"hellrazor" <jo***@another-world.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
Hi, (new to webservices here)

Is it possible to access a class instance variable defined in a webservice? I want to access this variable, in addition to the data being returned by
the [webmethod].

so let's say I have the following webservice class:
public class Service1 : System.Web.Services.WebService
{

public string hello2;

public ModelServices()
{
InitializeComponent();
}

[WebMethod]
public string sayHello()
{
hello2 = "another hello to you!"
return "hello there";
}
}
...............................

So when I consume this webservice, I want to be able to call the sayHello() method, and have access to the hello2 variable after having called sayHello () and thus expecting the "hello2" variable to contain the "another hello
to you!" value:
remoteWS.Service1 ws = new remoteWS.Service1();
string hello1 = ws.sayHello();
string hello2 = ws.hello2;

Is this possible, and how do I go about doing it? thanks!

Nov 21 '05 #3
I screwed up a bit of that code.

Please replace the client class as follows:

public void MyClient()
{
Service1 mywebservice;
SharedClass myShared;
myShared = mywebservice.SayHello();
Console.WriteLine("{0}", myShared.MyHello1);
Console.WriteLine("{0}", myShared.MyHello2);
}

Sorry about that.

--- Nick

"Nick Malik" <ni*******@hotmail.nospam.com> wrote in message
news:GKomd.513423$mD.491984@attbi_s02...
you can either add another webmethod to return the new value (which is
chatty and inefficient) or you can return a class that contains both values.
For example:

public class SharedClass
{
string MyHello1;
string MyHello2;
}

public class Service1: System.Web.Services.WebService
{
// put initializer here... ommitted for brevity
[WebMethod]
public SharedClass SayHello()
{
SharedClass sc = new SharedClass();
sc.MyHello1 = "Hello There";
sc.MyHello2 = "And Again";
}
}

public class WebClient
{
public void MyClient()
{
Service1 mywebservice;
mywebservice.SayHello();
Console.WriteLine("{0}", mywebservice.MyHello1);
Console.WriteLine("{0}", mywebservice.MyHello2);
}
}

((Caveat: this code is from the top of my head... it has not been
compiled... please excuse typos))

Hope this helps,
--- Nick

"hellrazor" <jo***@another-world.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
Hi, (new to webservices here)

Is it possible to access a class instance variable defined in a

webservice?
I want to access this variable, in addition to the data being returned by the [webmethod].

so let's say I have the following webservice class:
public class Service1 : System.Web.Services.WebService
{

public string hello2;

public ModelServices()
{
InitializeComponent();
}

[WebMethod]
public string sayHello()
{
hello2 = "another hello to you!"
return "hello there";
}
}
...............................

So when I consume this webservice, I want to be able to call the

sayHello()
method, and have access to the hello2 variable after having called

sayHello
() and thus expecting the "hello2" variable to contain the "another hello to you!" value:
remoteWS.Service1 ws = new remoteWS.Service1();
string hello1 = ws.sayHello();
string hello2 = ws.hello2;

Is this possible, and how do I go about doing it? thanks!


Nov 21 '05 #4
"Nick Malik" <ni*******@hotmail.nospam.com> wrote in news:q9pmd.46404
$5K2.39317@attbi_s03:
I screwed up a bit of that code.

Please replace the client class as follows:

public void MyClient()
{
Service1 mywebservice;
SharedClass myShared;
myShared = mywebservice.SayHello();
Console.WriteLine("{0}", myShared.MyHello1);
Console.WriteLine("{0}", myShared.MyHello2);
}

Sorry about that.

--- Nick

"Nick Malik" <ni*******@hotmail.nospam.com> wrote in message
news:GKomd.513423$mD.491984@attbi_s02...
you can either add another webmethod to return the new value (which is
chatty and inefficient) or you can return a class that contains both values.

For example:

public class SharedClass
{
string MyHello1;
string MyHello2;
}

public class Service1: System.Web.Services.WebService
{
// put initializer here... ommitted for brevity
[WebMethod]
public SharedClass SayHello()
{
SharedClass sc = new SharedClass();
sc.MyHello1 = "Hello There";
sc.MyHello2 = "And Again";
}
}

public class WebClient
{
public void MyClient()
{
Service1 mywebservice;
mywebservice.SayHello();
Console.WriteLine("{0}", mywebservice.MyHello1);
Console.WriteLine("{0}", mywebservice.MyHello2);
}
}

((Caveat: this code is from the top of my head... it has not been
compiled... please excuse typos))

Hope this helps,
--- Nick

"hellrazor" <jo***@another-world.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
> Hi, (new to webservices here)
>
> Is it possible to access a class instance variable defined in a

webservice?
> I want to access this variable, in addition to the data being
returned by > the [webmethod].
>
> so let's say I have the following webservice class:
>
>
> public class Service1 : System.Web.Services.WebService
> {
>
> public string hello2;
>
> public ModelServices()
> {
> InitializeComponent();
> }
>
> [WebMethod]
> public string sayHello()
> {
> hello2 = "another hello to you!"
> return "hello there";
> }
> }
>
>
> ...............................
>
> So when I consume this webservice, I want to be able to call the

sayHello()
> method, and have access to the hello2 variable after having called

sayHello
> () and thus expecting the "hello2" variable to contain the "another hello > to you!" value:
>
>
> remoteWS.Service1 ws = new remoteWS.Service1();
> string hello1 = ws.sayHello();
> string hello2 = ws.hello2;
>
>
>
> Is this possible, and how do I go about doing it? thanks!
>
>




Hi there, thanks!

When I try to compile the client application in VS, I get the following
error:

C:\clients\test.cs(1070): Cannot implicitly convert type
'WS.ReturnValuesClass' to 'MyApp.ReturnValuesClass'
I have placed the class in the source code for both the webservice and
the client. Is there anything specific involved that I have missed?

Thanks!

Jorge
Nov 21 '05 #5
<clip ...>
Hi there, thanks!

When I try to compile the client application in VS, I get the following
error:

C:\clients\test.cs(1070): Cannot implicitly convert type
'WS.ReturnValuesClass' to 'MyApp.ReturnValuesClass'
I have placed the class in the source code for both the webservice and
the client. Is there anything specific involved that I have missed?

Thanks!

Jorge


Hi Jorge,

That's what I get for not compiling the code first. My apologies.

The shared class should NOT be declared again in the client code. The
definition of the shared class is passed via the WSDL and is coded in the
web service generated code. You can simply declare a variable of type
WS.ReturnValuesClass and refer to the members that way.

If you want to see the code the Visual Studio generates for you when you
make a web reference, then look carefully at your project explorer window.
There are a couple of small icons in the bar just above the treeview of your
solution and project(s). One of the icons, if you hover over it, says
something like "show all files". Click it. Then look into the client
project. You will see a new code file under the web reference to the web
service. In there, you will see the definition of the shared class.

Good Luck,
--- Nick
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Erik P. Vinther | last post by:
Hi This might be slightly OT, but I couldn't find a better NG for this question The question is regarding versioning of webservices. A webservice end point URL basically consists of a base...
5
by: hellrazor | last post by:
Hi, (new to webservices here) Is it possible to access a class instance variable defined in a webservice? I want to access this variable, in addition to the data being returned by the . so...
1
by: Jinashe | last post by:
what do i need to enable accessing of webservices from a clients PC i'm hosting some webservices from my server in VB.NET. i've got some client windows applications done in VB.NET. what have i...
1
by: WStoreyII | last post by:
Two question, 1) is there a way to edit the interface of the display for when accessing a asmx file through the browser as opposed to that default web service interface. For example what if i...
6
by: sameer | last post by:
..NET Framework 1.1 VS2003 Application is making webservice calls from behind a proxy server and then freezes and dies. Questoin is can i use webservice over proxy server( i guess another name...
1
by: Jothi | last post by:
Hi, We are a small application development group. We have about 100 Users who primarily use Microsoft Related Products. Our Application Development was purley based on a CLient Server Model using...
10
by: smarty | last post by:
Hi, I have written a WSE in vis studio 2005 as and produced a dll that I can use in other projects by including the following in the web.config. <webservices> <soapextensiontypes> <add...
5
by: ChrisM | last post by:
Hi, I have written a stand alone WinForms application with an MS Access back-end for the (small)company I work for. They are now talking about moving a part of their operations into a second...
7
by: pthomet | last post by:
Another formulation of the message tittle could be : is it really "safe" (in the business sense) to embed a SSL webservice consumer into any given software, given that any time a proxy server will...
18
Ciary
by: Ciary | last post by:
good morning/afternoon/evening/night fellow coders, like a few times before i'm stuck with a problem. this time it hes everything to do with webservices or WCF. in the end, i want to convert an...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.