an architecture based on webservice

F

Francesco Spegni

hi there,

i hope this message is not out of topic. i've a question about how to
realize a small architecture based on webservice and whose goal is
ensure a good level o flexibility of my code.

in a few words: i've a webservice which exports the method
Authenticate(User usCurrUser). the data type User should be an
abstract class like this:

public abstract class User
{
public abstract bool Validate();
}

what i wish to do would be to create a subclass of it like

public abstract class UserSub : User
{
public UserSub(string strUserId, string strPassword)
{
...<the actual code>...
}

public override bool Validate()
{
...<the actual code>...
}
}

and pass an istance of the subclass to the webservice. the behavior i
expect is that the webservice, calling the abstract method Validate(),
will indeed call the Validate() method specified in the UserSub
class.

why all this? i guess you can easily imagine that if i'm able to
realize this i can change the way to authenticate my users (let's say
no more by userid and password but, instead, by fingerprints) without
need to change the proxy through which my client application calls the
webservice. i "just" need to change the webservice code and the client
code.

i've googled a bit, but i still cannot figure how to realize an
architecture like this. does any of you have some suggestion for my
problem?

i thank you in advance for any help you can give me,

have a nice day :)

francesco
 
J

John Saunders [MVP]

Francesco Spegni said:
hi there,

i hope this message is not out of topic. i've a question about how to
realize a small architecture based on webservice and whose goal is
ensure a good level o flexibility of my code.

in a few words: i've a webservice which exports the method
Authenticate(User usCurrUser). the data type User should be an
abstract class like this:

public abstract class User
{
public abstract bool Validate();
}

what i wish to do would be to create a subclass of it like

public abstract class UserSub : User
{
public UserSub(string strUserId, string strPassword)
{
...<the actual code>...
}

public override bool Validate()
{
...<the actual code>...
}
}

and pass an istance of the subclass to the webservice. the behavior i
expect is that the webservice, calling the abstract method Validate(),
will indeed call the Validate() method specified in the UserSub
class.

Francesco,

You can't do this with web services. They deal in data only. They cannot
pass instances of an object with methods. Consider the following:

public class UserBase
{
public virtual string SomeMethod()
{
return "UserBase";
}
}

public class UserDerived : UserBase
{
public override string SomeMethod()
{
return "UserDerived";
}
}

[WebService]
public class MyUserService
{
[WebMethod]
public void UserBase GetUser(int userID)
{
// look up user
// return user
}
}

-----------
On the client:

using (MyUserService service = new MyUserService())
{
UserBase user = service.GetUser(1);
Console.WriteLine(user.SomeMethod()); // Will not compile - no such
method
}

This will not compile because the client proxy class only reflects the
"data" portion of the UserBase and UserDerived classes. The data are
described by XML Schema that is referenced by the WSDL (Web Service
Description Language) that .NET generates from the web service. But there is
nothing in WSDL or XML Schema that can describe class methods (except for
the methods of a web service).


You could accomplish what you want through .NET remoting, if remote
operation is part of your requirements.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top