473,769 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Serv ices.WebService
{

public string hello2;

public ModelServices()
{
InitializeCompo nent();
}

[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.Servic e1 ws = new remoteWS.Servic e1();
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 1333
I don't think you can access a public member of
System.Web.Serv ices.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*****@hotmai l.com)
Blog: http://www.vbaspcoder.com
"hellrazor" <jo***@anothe r-world.com> wrote in message
news:Xn******** *************** ***********@207 .46.248.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.Serv ices.WebService
{

public string hello2;

public ModelServices()
{
InitializeCompo nent();
}

[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.Servic e1 ws = new remoteWS.Servic e1();
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.Serv ices.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.Sa yHello();
Console.WriteLi ne("{0}", mywebservice.My Hello1);
Console.WriteLi ne("{0}", mywebservice.My Hello2);
}
}

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

Hope this helps,
--- Nick

"hellrazor" <jo***@anothe r-world.com> wrote in message
news:Xn******** *************** ***********@207 .46.248.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.Serv ices.WebService
{

public string hello2;

public ModelServices()
{
InitializeCompo nent();
}

[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.Servic e1 ws = new remoteWS.Servic e1();
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.Sa yHello();
Console.WriteLi ne("{0}", myShared.MyHell o1);
Console.WriteLi ne("{0}", myShared.MyHell o2);
}

Sorry about that.

--- Nick

"Nick Malik" <ni*******@hotm ail.nospam.com> wrote in message
news:GKomd.5134 23$mD.491984@at tbi_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.Serv ices.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.Sa yHello();
Console.WriteLi ne("{0}", mywebservice.My Hello1);
Console.WriteLi ne("{0}", mywebservice.My Hello2);
}
}

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

Hope this helps,
--- Nick

"hellrazor" <jo***@anothe r-world.com> wrote in message
news:Xn******** *************** ***********@207 .46.248.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.Serv ices.WebService
{

public string hello2;

public ModelServices()
{
InitializeCompo nent();
}

[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.Servic e1 ws = new remoteWS.Servic e1();
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*******@hotm ail.nospam.com> wrote in news:q9pmd.4640 4
$5K2.39317@attb i_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.Sa yHello();
Console.WriteLi ne("{0}", myShared.MyHell o1);
Console.WriteLi ne("{0}", myShared.MyHell o2);
}

Sorry about that.

--- Nick

"Nick Malik" <ni*******@hotm ail.nospam.com> wrote in message
news:GKomd.5134 23$mD.491984@at tbi_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.Serv ices.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.Sa yHello();
Console.WriteLi ne("{0}", mywebservice.My Hello1);
Console.WriteLi ne("{0}", mywebservice.My Hello2);
}
}

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

Hope this helps,
--- Nick

"hellrazor" <jo***@anothe r-world.com> wrote in message
news:Xn******** *************** ***********@207 .46.248.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.Serv ices.WebService
> {
>
> public string hello2;
>
> public ModelServices()
> {
> InitializeCompo nent();
> }
>
> [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.Servic e1 ws = new remoteWS.Servic e1();
> 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.ReturnValue sClass' to 'MyApp.ReturnVa luesClass'
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.ReturnValue sClass' to 'MyApp.ReturnVa luesClass'
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.ReturnValues Class 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
1727
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 company URL and a webservice name, e.g… webservices.MyCompany.com/MyService we want to be able to host several versions of a particular webservice at the same time, so we want the version id to be part of the end point URL. This is consistent...
5
1571
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 let's say I have the following webservice class: public class Service1 : System.Web.Services.WebService
1
1361
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 got to install on the clients PC to be able to access these webservices?? Will just the .NET Framework suffice??? Or do i have to install SOAP?? note - the OS of the client can be win98, win2K, win3000, winXP
1
1496
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 wanted to use a dropdown list for one of the paramaters. if this is possible how html, xslt ? 2) can i assign a xslt style sheet to a xml webservices output. Lile instead of accessing the webservice from code. THe user can access the
6
2884
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 of them is ISA ... if i a not wrong), if yes how? Sameer
1
1159
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 Visual Basic and SQL Server. We plan to move forward to the .NET environment. We plan to develop applications with ASP.NEt as well as VB.NET. Right now we have some COM components or DLL's that we use. For example we
10
10580
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 type="traceextension, simpleModule" priority="1" group="high"/> </soapExtensionTypes> </webservices>
5
1846
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 site 50 miles away from the main one. The second site will simply be a stores. They will need some software in order to do a few things here, but this will probably come down to half a dozen or so main functions (booking stock in, issuing stock etc)
7
2248
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 be encountered, then the call will fail (based on my knowledge) ? ....Different Player, shoot again... I am asking a question which was posted several times in the last months, but never answered; any advice / insight would be appreciated. ...
18
10267
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 xml/access/SQL database (depends on what the user uploads) to a simple multi-dimentional array. but it isn't what i was trying to do now since i'm rather new to WCF. so, i started with a simple 'hello world' coding the webservice wasn't difficult,...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10043
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9861
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8869
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3956
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.