473,396 Members | 1,755 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,396 software developers and data experts.

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.sessionType == product1)
return product1.mehtod1;
}
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 1490
<da*****@gmail.comwrote in message
news:11**********************@y42g2000hsy.googlegr oups.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-
quitaestoparacontes...@poblacion.orgwrote:
<dan6...@gmail.comwrote in message

news:11**********************@y42g2000hsy.googlegr oups.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-
quitaestoparacontes...@poblacion.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 ServerGetGdsPort()
{
BaseObject workingBaseObject =
getProduct(serviceModeEnum);
return workingBaseObject.Port;
}

//BaseObject
....
private int port = Global.Configuration.PortNumber;
public int Port
{
get { return this.port; }
}

//Object that inherits from base
....
private int port = Global.Configuration.PortNumber;
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 ServerGetGdsPort()
{
BaseObject workingBaseObject =
getProduct(serviceModeEnum);
return workingBaseObject.Port;

}

//BaseObject
...
private int port = Global.Configuration.PortNumber;
public int Port
{
get { return this.port; }

}

//Object that inherits from base
...
private int port = Global.Configuration.PortNumber;
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 ServerGetGdsPort()
{
BaseObject workingBaseObject =
getProduct(serviceModeEnum);
return workingBaseObject.Port;

}

//BaseObject
...
private int port = Global.Configuration.PortNumber;
public virtual int Port
{
get { return this.port; }
}

//Object that inherits from base
...
private int port = Global.Configuration.PortNumber;
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
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...
4
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...
5
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...
5
by: mtv | last post by:
Hi all, I have the following code: ================================ Webservice side: public class MyWS: WebService { private myLib.DataObject curDataObject;
1
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...
3
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...
1
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...
4
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...
9
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
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.