WS Consumption: CType a return value of class to original class

Discussion in 'ASP .Net Web Services' started by MisterEd, Oct 26, 2004.

  1. MisterEd

    MisterEd Guest

    I am a new developer in an academic environment working on a project for
    graduation. I appreciate any help anyone can give me!

    I have tried to use good programming techniques and split up my application
    into different tiers: Win (windows client), WS (web service), DAL (data
    access layer), and Common (where i store all of my common classes and data
    sets).

    I have a class in my Common tier that is called User. It has some members
    and also has two functions in it.

    I have a web method called GetUser() and it returns a value of type
    Common.User.

    In my Win application I want to consume the web service and return a user of
    the Common.User type such as this example:
    Dim CurrentUser as new Common.User
    CurrentUser = CType(UsersWS.GetUser(), Common.User)

    My problem comes because I am getting an error in the conversion: [Value of
    type 'UsersWS.User' cannot be converted to 'Common.User']. This is really
    frustrating because if I make the CurrentUser variable of type UsersWS.User,
    then I can't use the functions that I have built into the Users class, only
    the data members.

    I have thought of everything and even changed my declaration of the class
    User in my Common Tier to:

    <Serializable()> Public Class User : Inherits System.MashalByRefObject

    so that an object of this type could cross application domains.

    --I'm not sure what to do at this point but I would love for that conversion
    to work. Maybe I am just missing something simple (hopefully!).

    Anyhow, thanks for any help!

    Ed
     
    MisterEd, Oct 26, 2004
    #1
    1. Advertising

  2. Hi Ed,

    You can't do it that way. You need to create the type from the web service
    itself:

    Dim CurrentUser As New UsersWS.Common.User()
    CurrentUser = UsersWS.GetUser()

    That should make it work. Good luck! Ken.

    --
    Ken Dopierala Jr.
    For great ASP.Net web hosting try:
    http://www.webhost4life.com/default.asp?refid=Spinlight
    If you sign up under me and need help, email me.

    "MisterEd" <> wrote in message
    news:...
    > I am a new developer in an academic environment working on a project for
    > graduation. I appreciate any help anyone can give me!
    >
    > I have tried to use good programming techniques and split up my

    application
    > into different tiers: Win (windows client), WS (web service), DAL (data
    > access layer), and Common (where i store all of my common classes and data
    > sets).
    >
    > I have a class in my Common tier that is called User. It has some members
    > and also has two functions in it.
    >
    > I have a web method called GetUser() and it returns a value of type
    > Common.User.
    >
    > In my Win application I want to consume the web service and return a user

    of
    > the Common.User type such as this example:
    > Dim CurrentUser as new Common.User
    > CurrentUser = CType(UsersWS.GetUser(), Common.User)
    >
    > My problem comes because I am getting an error in the conversion: [Value

    of
    > type 'UsersWS.User' cannot be converted to 'Common.User']. This is really
    > frustrating because if I make the CurrentUser variable of type

    UsersWS.User,
    > then I can't use the functions that I have built into the Users class,

    only
    > the data members.
    >
    > I have thought of everything and even changed my declaration of the class
    > User in my Common Tier to:
    >
    > <Serializable()> Public Class User : Inherits System.MashalByRefObject
    >
    > so that an object of this type could cross application domains.
    >
    > --I'm not sure what to do at this point but I would love for that

    conversion
    > to work. Maybe I am just missing something simple (hopefully!).
    >
    > Anyhow, thanks for any help!
    >
    > Ed
     
    Ken Dopierala Jr., Oct 27, 2004
    #2
    1. Advertising

  3. MisterEd

    MisterEd Guest

    Re: WS Consumption: CType a return value of class to original clas

    Thanks for the help!

    The only problem is that I would like to use two member functions that I
    have written for the User class. For some reason, whenever I call the
    webservice, the UsersWS.User class does not have those functions.

    Is there any way I can get it to convert back to that same base (I'm not
    sure this is the proper term) class with the member functions?

    Thanks again,
    Ed

    "Ken Dopierala Jr." wrote:

    > Hi Ed,
    >
    > You can't do it that way. You need to create the type from the web service
    > itself:
    >
    > Dim CurrentUser As New UsersWS.Common.User()
    > CurrentUser = UsersWS.GetUser()
    >
    > That should make it work. Good luck! Ken.
    >
    > --
    > Ken Dopierala Jr.
    > For great ASP.Net web hosting try:
    > http://www.webhost4life.com/default.asp?refid=Spinlight
    > If you sign up under me and need help, email me.
    >
    > "MisterEd" <> wrote in message
    > news:...
    > > I am a new developer in an academic environment working on a project for
    > > graduation. I appreciate any help anyone can give me!
    > >
    > > I have tried to use good programming techniques and split up my

    > application
    > > into different tiers: Win (windows client), WS (web service), DAL (data
    > > access layer), and Common (where i store all of my common classes and data
    > > sets).
    > >
    > > I have a class in my Common tier that is called User. It has some members
    > > and also has two functions in it.
    > >
    > > I have a web method called GetUser() and it returns a value of type
    > > Common.User.
    > >
    > > In my Win application I want to consume the web service and return a user

    > of
    > > the Common.User type such as this example:
    > > Dim CurrentUser as new Common.User
    > > CurrentUser = CType(UsersWS.GetUser(), Common.User)
    > >
    > > My problem comes because I am getting an error in the conversion: [Value

    > of
    > > type 'UsersWS.User' cannot be converted to 'Common.User']. This is really
    > > frustrating because if I make the CurrentUser variable of type

    > UsersWS.User,
    > > then I can't use the functions that I have built into the Users class,

    > only
    > > the data members.
    > >
    > > I have thought of everything and even changed my declaration of the class
    > > User in my Common Tier to:
    > >
    > > <Serializable()> Public Class User : Inherits System.MashalByRefObject
    > >
    > > so that an object of this type could cross application domains.
    > >
    > > --I'm not sure what to do at this point but I would love for that

    > conversion
    > > to work. Maybe I am just missing something simple (hopefully!).
    > >
    > > Anyhow, thanks for any help!
    > >
    > > Ed

    >
    >
    >
     
    MisterEd, Oct 28, 2004
    #3
  4. Re: WS Consumption: CType a return value of class to original clas

    Hi Ed,

    I don't believe you can serialize executable code through a web service. I
    would create a business logic layer that accepts your class as a parameter
    (make sure your business logic layer is using a class based on a type from
    the web service and not from the Common.User class directly), then have this
    layer consume the class you receive through the web service. Good luck!
    Ken.

    --
    Ken Dopierala Jr.
    For great ASP.Net web hosting try:
    http://www.webhost4life.com/default.asp?refid=Spinlight
    If you sign up under me and need help, email me.

    "MisterEd" <> wrote in message
    news:...
    > Thanks for the help!
    >
    > The only problem is that I would like to use two member functions that I
    > have written for the User class. For some reason, whenever I call the
    > webservice, the UsersWS.User class does not have those functions.
    >
    > Is there any way I can get it to convert back to that same base (I'm not
    > sure this is the proper term) class with the member functions?
    >
    > Thanks again,
    > Ed
    >
    > "Ken Dopierala Jr." wrote:
    >
    > > Hi Ed,
    > >
    > > You can't do it that way. You need to create the type from the web

    service
    > > itself:
    > >
    > > Dim CurrentUser As New UsersWS.Common.User()
    > > CurrentUser = UsersWS.GetUser()
    > >
    > > That should make it work. Good luck! Ken.
    > >
    > > --
    > > Ken Dopierala Jr.
    > > For great ASP.Net web hosting try:
    > > http://www.webhost4life.com/default.asp?refid=Spinlight
    > > If you sign up under me and need help, email me.
    > >
    > > "MisterEd" <> wrote in message
    > > news:...
    > > > I am a new developer in an academic environment working on a project

    for
    > > > graduation. I appreciate any help anyone can give me!
    > > >
    > > > I have tried to use good programming techniques and split up my

    > > application
    > > > into different tiers: Win (windows client), WS (web service), DAL

    (data
    > > > access layer), and Common (where i store all of my common classes and

    data
    > > > sets).
    > > >
    > > > I have a class in my Common tier that is called User. It has some

    members
    > > > and also has two functions in it.
    > > >
    > > > I have a web method called GetUser() and it returns a value of type
    > > > Common.User.
    > > >
    > > > In my Win application I want to consume the web service and return a

    user
    > > of
    > > > the Common.User type such as this example:
    > > > Dim CurrentUser as new Common.User
    > > > CurrentUser = CType(UsersWS.GetUser(), Common.User)
    > > >
    > > > My problem comes because I am getting an error in the conversion:

    [Value
    > > of
    > > > type 'UsersWS.User' cannot be converted to 'Common.User']. This is

    really
    > > > frustrating because if I make the CurrentUser variable of type

    > > UsersWS.User,
    > > > then I can't use the functions that I have built into the Users class,

    > > only
    > > > the data members.
    > > >
    > > > I have thought of everything and even changed my declaration of the

    class
    > > > User in my Common Tier to:
    > > >
    > > > <Serializable()> Public Class User : Inherits System.MashalByRefObject
    > > >
    > > > so that an object of this type could cross application domains.
    > > >
    > > > --I'm not sure what to do at this point but I would love for that

    > > conversion
    > > > to work. Maybe I am just missing something simple (hopefully!).
    > > >
    > > > Anyhow, thanks for any help!
    > > >
    > > > Ed

    > >
    > >
    > >
     
    Ken Dopierala Jr., Oct 28, 2004
    #4
  5. MisterEd

    MisterEd Guest

    Re: WS Consumption: CType a return value of class to original clas

    That sounds like the way I am going to have to do it. Thanks again for the
    help!

    "Ken Dopierala Jr." wrote:

    > Hi Ed,
    >
    > I don't believe you can serialize executable code through a web service. I
    > would create a business logic layer that accepts your class as a parameter
    > (make sure your business logic layer is using a class based on a type from
    > the web service and not from the Common.User class directly), then have this
    > layer consume the class you receive through the web service. Good luck!
    > Ken.
    >
    > --
    > Ken Dopierala Jr.
    > For great ASP.Net web hosting try:
    > http://www.webhost4life.com/default.asp?refid=Spinlight
    > If you sign up under me and need help, email me.
    >
    > "MisterEd" <> wrote in message
    > news:...
    > > Thanks for the help!
    > >
    > > The only problem is that I would like to use two member functions that I
    > > have written for the User class. For some reason, whenever I call the
    > > webservice, the UsersWS.User class does not have those functions.
    > >
    > > Is there any way I can get it to convert back to that same base (I'm not
    > > sure this is the proper term) class with the member functions?
    > >
    > > Thanks again,
    > > Ed
    > >
    > > "Ken Dopierala Jr." wrote:
    > >
    > > > Hi Ed,
    > > >
    > > > You can't do it that way. You need to create the type from the web

    > service
    > > > itself:
    > > >
    > > > Dim CurrentUser As New UsersWS.Common.User()
    > > > CurrentUser = UsersWS.GetUser()
    > > >
    > > > That should make it work. Good luck! Ken.
    > > >
    > > > --
    > > > Ken Dopierala Jr.
    > > > For great ASP.Net web hosting try:
    > > > http://www.webhost4life.com/default.asp?refid=Spinlight
    > > > If you sign up under me and need help, email me.
    > > >
    > > > "MisterEd" <> wrote in message
    > > > news:...
    > > > > I am a new developer in an academic environment working on a project

    > for
    > > > > graduation. I appreciate any help anyone can give me!
    > > > >
    > > > > I have tried to use good programming techniques and split up my
    > > > application
    > > > > into different tiers: Win (windows client), WS (web service), DAL

    > (data
    > > > > access layer), and Common (where i store all of my common classes and

    > data
    > > > > sets).
    > > > >
    > > > > I have a class in my Common tier that is called User. It has some

    > members
    > > > > and also has two functions in it.
    > > > >
    > > > > I have a web method called GetUser() and it returns a value of type
    > > > > Common.User.
    > > > >
    > > > > In my Win application I want to consume the web service and return a

    > user
    > > > of
    > > > > the Common.User type such as this example:
    > > > > Dim CurrentUser as new Common.User
    > > > > CurrentUser = CType(UsersWS.GetUser(), Common.User)
    > > > >
    > > > > My problem comes because I am getting an error in the conversion:

    > [Value
    > > > of
    > > > > type 'UsersWS.User' cannot be converted to 'Common.User']. This is

    > really
    > > > > frustrating because if I make the CurrentUser variable of type
    > > > UsersWS.User,
    > > > > then I can't use the functions that I have built into the Users class,
    > > > only
    > > > > the data members.
    > > > >
    > > > > I have thought of everything and even changed my declaration of the

    > class
    > > > > User in my Common Tier to:
    > > > >
    > > > > <Serializable()> Public Class User : Inherits System.MashalByRefObject
    > > > >
    > > > > so that an object of this type could cross application domains.
    > > > >
    > > > > --I'm not sure what to do at this point but I would love for that
    > > > conversion
    > > > > to work. Maybe I am just missing something simple (hopefully!).
    > > > >
    > > > > Anyhow, thanks for any help!
    > > > >
    > > > > Ed
    > > >
    > > >
    > > >

    >
    >
    >
     
    MisterEd, Oct 28, 2004
    #5
  6. Re: WS Consumption: CType a return value of class to original clas

    you could of course, modify the generated proxy class to reference your own
    type. This will work if you are sure that both your type and the generated
    type serialize to the same XML.


    "MisterEd" <> wrote in message
    news:...
    > That sounds like the way I am going to have to do it. Thanks again for
    > the
    > help!
    >
    > "Ken Dopierala Jr." wrote:
    >
    >> Hi Ed,
    >>
    >> I don't believe you can serialize executable code through a web service.
    >> I
    >> would create a business logic layer that accepts your class as a
    >> parameter
    >> (make sure your business logic layer is using a class based on a type
    >> from
    >> the web service and not from the Common.User class directly), then have
    >> this
    >> layer consume the class you receive through the web service. Good luck!
    >> Ken.
    >>
    >> --
    >> Ken Dopierala Jr.
    >> For great ASP.Net web hosting try:
    >> http://www.webhost4life.com/default.asp?refid=Spinlight
    >> If you sign up under me and need help, email me.
    >>
    >> "MisterEd" <> wrote in message
    >> news:...
    >> > Thanks for the help!
    >> >
    >> > The only problem is that I would like to use two member functions that
    >> > I
    >> > have written for the User class. For some reason, whenever I call the
    >> > webservice, the UsersWS.User class does not have those functions.
    >> >
    >> > Is there any way I can get it to convert back to that same base (I'm
    >> > not
    >> > sure this is the proper term) class with the member functions?
    >> >
    >> > Thanks again,
    >> > Ed
    >> >
    >> > "Ken Dopierala Jr." wrote:
    >> >
    >> > > Hi Ed,
    >> > >
    >> > > You can't do it that way. You need to create the type from the web

    >> service
    >> > > itself:
    >> > >
    >> > > Dim CurrentUser As New UsersWS.Common.User()
    >> > > CurrentUser = UsersWS.GetUser()
    >> > >
    >> > > That should make it work. Good luck! Ken.
    >> > >
    >> > > --
    >> > > Ken Dopierala Jr.
    >> > > For great ASP.Net web hosting try:
    >> > > http://www.webhost4life.com/default.asp?refid=Spinlight
    >> > > If you sign up under me and need help, email me.
    >> > >
    >> > > "MisterEd" <> wrote in message
    >> > > news:...
    >> > > > I am a new developer in an academic environment working on a
    >> > > > project

    >> for
    >> > > > graduation. I appreciate any help anyone can give me!
    >> > > >
    >> > > > I have tried to use good programming techniques and split up my
    >> > > application
    >> > > > into different tiers: Win (windows client), WS (web service), DAL

    >> (data
    >> > > > access layer), and Common (where i store all of my common classes
    >> > > > and

    >> data
    >> > > > sets).
    >> > > >
    >> > > > I have a class in my Common tier that is called User. It has some

    >> members
    >> > > > and also has two functions in it.
    >> > > >
    >> > > > I have a web method called GetUser() and it returns a value of type
    >> > > > Common.User.
    >> > > >
    >> > > > In my Win application I want to consume the web service and return
    >> > > > a

    >> user
    >> > > of
    >> > > > the Common.User type such as this example:
    >> > > > Dim CurrentUser as new Common.User
    >> > > > CurrentUser = CType(UsersWS.GetUser(), Common.User)
    >> > > >
    >> > > > My problem comes because I am getting an error in the conversion:

    >> [Value
    >> > > of
    >> > > > type 'UsersWS.User' cannot be converted to 'Common.User']. This is

    >> really
    >> > > > frustrating because if I make the CurrentUser variable of type
    >> > > UsersWS.User,
    >> > > > then I can't use the functions that I have built into the Users
    >> > > > class,
    >> > > only
    >> > > > the data members.
    >> > > >
    >> > > > I have thought of everything and even changed my declaration of the

    >> class
    >> > > > User in my Common Tier to:
    >> > > >
    >> > > > <Serializable()> Public Class User : Inherits
    >> > > > System.MashalByRefObject
    >> > > >
    >> > > > so that an object of this type could cross application domains.
    >> > > >
    >> > > > --I'm not sure what to do at this point but I would love for that
    >> > > conversion
    >> > > > to work. Maybe I am just missing something simple (hopefully!).
    >> > > >
    >> > > > Anyhow, thanks for any help!
    >> > > >
    >> > > > Ed
    >> > >
    >> > >
    >> > >

    >>
    >>
    >>
     
    Dino Chiesa [Microsoft], Oct 28, 2004
    #6
    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. =?Utf-8?B?U2FuZHk=?=

    Return user to original view

    =?Utf-8?B?U2FuZHk=?=, Apr 18, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    364
    =?Utf-8?B?QnJpYW4gRmFybmhpbGwgKE1DUCBWQi5ORVQp?=
    Apr 21, 2005
  2. Neena
    Replies:
    2
    Views:
    842
    Roedy Green
    Sep 28, 2005
  3. Replies:
    0
    Views:
    536
  4. Greenhorn
    Replies:
    15
    Views:
    834
    Keith Thompson
    Mar 6, 2005
  5. hg
    Replies:
    2
    Views:
    394
Loading...

Share This Page