473,569 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

design advise selecting object for webservice methods

Hello,
I've come here to get some advise from the experts. Currently I am
tasked with modifying a web service that currently supports one
product to support multiple products. It needs to be backwards
compatible so other products still work with the same method calls and
the new products need to have methods with the same names, but
different logic.

Currently we keep some credential information from the client that
consumes the service in a session object that we've created upon them
logging in. I've added the product type to the session object.

I have created new object types for each new product that inherit from
the original object which includes all of the methods and override
methods that require different logic.

I would like to know how I could implement this so that when a
webservice method call comes in with a session variable passed that
contains the product type that the correct object's method is called.

i.e.

[WebMethod]
method1(Session session)
{
if (session.sessio nType == product1)
return product1.mehtod 1;
}
is there any way I can do this without using if/else or switch logic
in each webservice method? I was thinking of a function that maps the
session and returns a type so I can cast from the base object. But I
do not know how to do this, or if it is even possible. Thanks guys!

Sep 4 '07 #1
4 1502
<da*****@gmail. comwrote in message
news:11******** **************@ y42g2000hsy.goo glegroups.com.. .
>[...] I've added the product type to the session object.

I have created new object types for each new product that inherit from
the original object which includes all of the methods and override
methods that require different logic.

[...]

is there any way I can do this without using if/else or switch logic
in each webservice method? I was thinking of a function that maps the
session and returns a type so I can cast from the base object. But I
do not know how to do this, or if it is even possible. Thanks guys!
If the various objects types for the different products are not too big
(they do not contain a lot of instance data), you could consider storing the
objects themselves (instead of their types) in the Session. In this way,
your web methods could just retrieve the object from the Session, cast it to
the base type, and call the corresponding method just the way you wanted.

If this is not suitable, you could put your "if/else or switch logic"
(that provides the adequate object from its type) inside a specific private
method that returns the base class for your products. Then call this private
method at the beginning of all your web methods and invoke the proper method
on the object returned.

If the switch logic becomes too big, you could simplify it by using
Reflection to create an object from the name of the type (stored in
Session), but I think that this is overkill and the single method containing
the switch statement should solve the problem quite nicely.

Sep 4 '07 #2
On Sep 4, 3:59 pm, "Alberto Poblacion" <earthling-
quitaestoparaco ntes...@poblaci on.orgwrote:
<dan6...@gmail. comwrote in message

news:11******** **************@ y42g2000hsy.goo glegroups.com.. .
[...] I've added the product type to the session object.
I have created new object types for each new product that inherit from
the original object which includes all of the methods and override
methods that require different logic.
[...]
is there any way I can do this without using if/else or switch logic
in each webservice method? I was thinking of a function that maps the
session and returns a type so I can cast from the base object. But I
do not know how to do this, or if it is even possible. Thanks guys!

If the various objects types for the different products are not too big
(they do not contain a lot of instance data), you could consider storing the
objects themselves (instead of their types) in the Session. In this way,
your web methods could just retrieve the object from the Session, cast it to
the base type, and call the corresponding method just the way you wanted.

If this is not suitable, you could put your "if/else or switch logic"
(that provides the adequate object from its type) inside a specific private
method that returns the base class for your products. Then call this private
method at the beginning of all your web methods and invoke the proper method
on the object returned.

If the switch logic becomes too big, you could simplify it by using
Reflection to create an object from the name of the type (stored in
Session), but I think that this is overkill and the single method containing
the switch statement should solve the problem quite nicely.
I will probably go forward with the second approach. The first and
third are good ideas, and I'm glad you mentioned them. Thanks so much
for the help.

Sep 5 '07 #3
On Sep 4, 3:59 pm, "Alberto Poblacion" <earthling-
quitaestoparaco ntes...@poblaci on.orgwrote:
If this is not suitable, you could put your "if/else or switch logic"
(that provides the adequate object from its type) inside a specific private
method that returns the base class for your products. Then call this private
method at the beginning of all your web methods and invoke the proper method
on the object returned.
I have a question about implementing this approach. When I call a
function in the object returned by the private method it always uses
the logic in the base class, rather than the class that inherits the
logic. Perhaps I am missing something...

//WebService
[WebMethod()]
public int ServerGetGdsPor t()
{
BaseObject workingBaseObje ct =
getProduct(serv iceModeEnum);
return workingBaseObje ct.Port;
}

//BaseObject
....
private int port = Global.Configur ation.PortNumbe r;
public int Port
{
get { return this.port; }
}

//Object that inherits from base
....
private int port = Global.Configur ation.PortNumbe r;
public new int Port
{
get { return this.port; }
}

Is there any way to use the logic in my inhered class here?

Thanks,
Danny

Sep 11 '07 #4
I have a question about implementing this approach. When I call a
function in the object returned by the private method it always uses
the logic in the base class, rather than the class that inherits the
logic. Perhaps I am missing something...

//WebService
[WebMethod()]
public int ServerGetGdsPor t()
{
BaseObject workingBaseObje ct =
getProduct(serv iceModeEnum);
return workingBaseObje ct.Port;

}

//BaseObject
...
private int port = Global.Configur ation.PortNumbe r;
public int Port
{
get { return this.port; }

}

//Object that inherits from base
...
private int port = Global.Configur ation.PortNumbe r;
public new int Port
{
get { return this.port; }

}

Is there any way to use the logic in my inhered class here?

Thanks,
Danny
I should have tried a little harder before posting. Anyway, to make
things complete I'll include the answer to my question.

I had to add the virtual identifier to the properties in the base
class and the override identifier to the ones in the derived class:

//WebService
[WebMethod()]
public int ServerGetGdsPor t()
{
BaseObject workingBaseObje ct =
getProduct(serv iceModeEnum);
return workingBaseObje ct.Port;

}

//BaseObject
...
private int port = Global.Configur ation.PortNumbe r;
public virtual int Port
{
get { return this.port; }
}

//Object that inherits from base
...
private int port = Global.Configur ation.PortNumbe r;
public override new int Port
{
get { return this.port; }
}

Now the logic which returns an object of the base class's type (that
is declared as an inherited object) works!

-Danny
Sep 11 '07 #5

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

Similar topics

5
1777
by: Nick Malik | last post by:
reposting to a wider audience "Nick Malik" <nickmalik@hotmail.nospam.com> wrote in message news:WYONc.203854$XM6.119642@attbi_s53... > My turn to ask a question > > I am working on a plug-in for Sharepoint that will allow a developer to add > workflow rules. One of the rules will inform the adapter that it should > load a DLL that the...
4
1424
by: Nick Malik | last post by:
My turn to ask a question I am working on a plug-in for Sharepoint that will allow a developer to add workflow rules. One of the rules will inform the adapter that it should load a DLL that the developer writes, find a method that matches a particular interface, and call it. I know, in general, I should be looking at the reflection...
5
5138
by: hellrazor | last post by:
Hi there, I'm very new to dot net programming and webservices programming. I've managed to create simple webservices so far. Here's my problem: -I've been given a project which needs to have a proprietary algorithm split into a webservice.
5
6900
by: mtv | last post by:
Hi all, I have the following code: ================================ Webservice side: public class MyWS: WebService { private myLib.DataObject curDataObject;
1
1221
by: kamig | last post by:
Hey! guys i have this annoying question i have upgrade my webService project from visual studion.NET 2003 to 2005 but the problem is tht i cant access my webService directly from iis mmc by click the .asmx and selecting browsing in old days of .net 2003.....it gives an error like that user initiated the asp.net process should have access to...
3
1365
by: John S | last post by:
I've got to produce a console app that requests a dataset from a web service in our personnel system, manipulates the data and then updates each record in the Active directory. Not being the most brilliant OOP programmer I'm having problems trying to design suitable objects. Would anyone like to suggest how they would design this type of...
1
1105
by: D-Someone | last post by:
I am re-posting this message as originially it did not get a single response.. Any ideas? -------------- I am trying to come up with a good design for a web service that has some user logic and business processes involved. Here a small sample of the process flow: --- Client Get's User Input for field 1...
4
1320
by: John Sitka | last post by:
Hi, sorry for a crosspost but that other news group was showing last post was a week ago so I guess it dosen't see much use... I'm about to start a solution and I'm curious about the approach of a webservices project. Should the objects be represented in classes such as... public class Orders (ie Orders.cs) within a project and then have...
9
1687
by: Jens Jensen | last post by:
Hello all, I need some design advice for my web service. I' have written a web service that exposes a function that takes some parameters and return an xml.
0
7614
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...
0
8125
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...
0
7974
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...
0
6284
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...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
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...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2114
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
1
1221
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.