an architecture based on webservice

Discussion in 'ASP .Net' started by Francesco Spegni, Jun 19, 2007.

  1. 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
    Francesco Spegni, Jun 19, 2007
    #1
    1. Advertising

  2. "Francesco Spegni" <> wrote in message
    news:...
    > 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.
    --
    John Saunders [MVP]
    John Saunders [MVP], Jun 19, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Muhammad Khan
    Replies:
    4
    Views:
    1,209
    Mike Treseler
    Jul 10, 2003
  2. Replies:
    3
    Views:
    502
    Malcolm
    Sep 29, 2005
  3. rashmi
    Replies:
    2
    Views:
    445
    Grumble
    Jul 5, 2005
  4. Replies:
    3
    Views:
    414
    Malcolm
    Sep 29, 2005
  5. Replies:
    4
    Views:
    650
    Malcolm
    Sep 29, 2005
Loading...

Share This Page