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

M

MisterEd

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
 
K

Ken Dopierala Jr.

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.
 
M

MisterEd

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. said:
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 said:
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
 
K

Ken Dopierala Jr.

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 said:
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. said:
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 said:
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
 
M

MisterEd

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

Ken Dopierala Jr. said:
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 said:
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. said:
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.

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
 
D

Dino Chiesa [Microsoft]

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 said:
That sounds like the way I am going to have to do it. Thanks again for
the
help!

Ken Dopierala Jr. said:
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 said:
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

:

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.

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
 

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

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top