Class structure / VS.net question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rob Andrew

    Class structure / VS.net question

    Hi All,

    I'm new to VS.net, coming from Delphi, and there is something that I'm
    trying to clarify in my head about VS.net.

    Suppose you had a class Employee (Name, Age, Title, etc).

    Lets further assume that you are creating a web service, with a .net
    windows application as a client to that web service. Given that you
    wish to share the structure of the Employee class between client and
    web service (which occurs with the auto generation of a proxy class),
    all is fine.

    Is there a way of structuring your code so that you can make use of
    only one copy of the Employee class? Im not trying to get the method
    itself over the web service, but rather allowing my already defined
    class to be used in two places (the web service and the client
    application).

    For instance, can you call upon a method (say calculateSalary [which
    perhaps adds 2 numbers together]) without going to the webservice and
    hence back to the original class itself for the method (which is not
    transferred over the web service)? So we would compile the class into
    two separate assemblies?

    Thanks, Rob
  • recoil@community.nospam

    #2
    Re: Class structure / VS.net question

    The Proxy only replicates properties and Web Service methods.
    Definition of what this means
    [WebMethod]
    public MyDatatype[] AMethod(int32 parameter)
    {
    return an array of MyDataType[]
    }
    class MyDataType
    { public property MyName
    override ToString() { return MyName; }
    }


    If the web service is used in a reference and you add the object to a
    listbox instead of seeing the value of MyName it will show
    {MNameSpace.MyD ataType}.

    Sharing the same logic code such as the above example between a web
    service and a client is extremely painful imho. Often times I have
    logic that needs to be performed by the client but does not need to be
    performed by the web service. When this happens i create a MyDataTypeEx
    which has a constructor overload that accepts a MyDataType (this is
    useful for arrays since you cannot convert MyDataType[] to
    MyDataTypeEx. This approach may actually be usable in a scenario where
    one needs logic to be usable by both sides. You could have your
    Extended class which has all the shared logic in a separate satellite
    assembly. You never publicly expose these methods via the web service.
    The only real major issue I see here is that you have the overhead of
    going back and forth between Object and ExtendedObject .

    I think there is a reason why web services are still not a common sight
    and this is one of the many reasons why. Currently web services are a
    semi-decent means to communicate and from my experience you really
    should not be attempting to communicate anything overly complex,
    otherwise the limitations start weighing in heavily.

    Comment

    Working...