Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > Getting unable to cast error (when same object is referenced in client and web service)

Reply
Thread Tools

Getting unable to cast error (when same object is referenced in client and web service)

 
 
Rahul
Guest
Posts: n/a
 
      01-14-2008
I am getting following error:

1) For a xml file "Request.xml" we created a schema "Request.xsd".

2) With the help of xsd.exe we got the C# file Request.cs.

3) We tried to send the object of Request.cs to a webservice method
SaveRequest(Request req).

4) Scenario is like same Request.cs is referenced by both server and
client.

5)When we are trying to pass the req object of type Request we are getting
unable to cast error.

Is this expected? If so, are there any workarounds?


Please help us in solving this.

Thanks !!!!!



 
Reply With Quote
 
 
 
 
John Saunders [MVP]
Guest
Posts: n/a
 
      01-14-2008
"Rahul" <> wrote in message
news:...
>I am getting following error:
>
> 1) For a xml file "Request.xml" we created a schema "Request.xsd".
>
> 2) With the help of xsd.exe we got the C# file Request.cs.
>
> 3) We tried to send the object of Request.cs to a webservice method
> SaveRequest(Request req).
>
> 4) Scenario is like same Request.cs is referenced by both server and
> client.
>
> 5)When we are trying to pass the req object of type Request we are getting
> unable to cast error.
>
> Is this expected? If so, are there any workarounds?


This is expected. The classes on the client side are proxy classes only -
they are not meant to be the same as the server-side classes. Their only
purpose is to make it easier for you to call the web methods exposed by the
server.

In fact, if you ever get a situation with ASMX web services where you have
the same class on the client and the server, then you've almost certainly
made a very serious mistake.
--
--------------------------------------------------------------------------------
John Saunders | MVP - Windows Server System - Connected System Developer


 
Reply With Quote
 
 
 
 
william
Guest
Posts: n/a
 
      02-27-2008
Hi John,
I've went through similar steps as Rahul, which is that I created a class by
using xsd.exe, I have a web service which return this serialized class. I
declared a variable as this class, and assign the return value of my web
service to the variable, I got compiling error "Cannot implicitly convert
type MyWebServiceTest.MyService.GetUserInfoResponseGetU serInfoResult to
User".

How can I get result from my web service?

Thanks.

William

"John Saunders [MVP]" wrote:

> "Rahul" <> wrote in message
> news:...
> >I am getting following error:
> >
> > 1) For a xml file "Request.xml" we created a schema "Request.xsd".
> >
> > 2) With the help of xsd.exe we got the C# file Request.cs.
> >
> > 3) We tried to send the object of Request.cs to a webservice method
> > SaveRequest(Request req).
> >
> > 4) Scenario is like same Request.cs is referenced by both server and
> > client.
> >
> > 5)When we are trying to pass the req object of type Request we are getting
> > unable to cast error.
> >
> > Is this expected? If so, are there any workarounds?

>
> This is expected. The classes on the client side are proxy classes only -
> they are not meant to be the same as the server-side classes. Their only
> purpose is to make it easier for you to call the web methods exposed by the
> server.
>
> In fact, if you ever get a situation with ASMX web services where you have
> the same class on the client and the server, then you've almost certainly
> made a very serious mistake.
> --
> --------------------------------------------------------------------------------
> John Saunders | MVP - Windows Server System - Connected System Developer
>
>
>

 
Reply With Quote
 
John Saunders [MVP]
Guest
Posts: n/a
 
      02-28-2008
"william" <> wrote in message
news:2FD9A030-6F77-44E3-B1F0-...
> Hi John,
> I've went through similar steps as Rahul, which is that I created a class
> by
> using xsd.exe, I have a web service which return this serialized class. I
> declared a variable as this class, and assign the return value of my web
> service to the variable, I got compiling error "Cannot implicitly convert
> type MyWebServiceTest.MyService.GetUserInfoResponseGetU serInfoResult to
> User".
>
> How can I get result from my web service?


William, that error message you posted seems to be cut off. Surely the
message doesn't end with the word "User".
--
--------------------------------------------------------------------------------
John Saunders | MVP - Windows Server System - Connected System Developer


 
Reply With Quote
 
william
Guest
Posts: n/a
 
      02-29-2008
Hi John,

Actually my class name is "User", I declares a type as "User" on client
side, and tried to assign the return value of web service to it.Thanks.

William

"John Saunders [MVP]" wrote:

> "william" <> wrote in message
> news:2FD9A030-6F77-44E3-B1F0-...
> > Hi John,
> > I've went through similar steps as Rahul, which is that I created a class
> > by
> > using xsd.exe, I have a web service which return this serialized class. I
> > declared a variable as this class, and assign the return value of my web
> > service to the variable, I got compiling error "Cannot implicitly convert
> > type MyWebServiceTest.MyService.GetUserInfoResponseGetU serInfoResult to
> > User".
> >
> > How can I get result from my web service?

>
> William, that error message you posted seems to be cut off. Surely the
> message doesn't end with the word "User".
> --
> --------------------------------------------------------------------------------
> John Saunders | MVP - Windows Server System - Connected System Developer
>
>
>

 
Reply With Quote
 
John Saunders [MVP]
Guest
Posts: n/a
 
      03-01-2008
"william" <> wrote in message
news:8A94D21B-C301-43E2-8079-...
> Hi John,
>
> Actually my class name is "User", I declares a type as "User" on client
> side, and tried to assign the return value of web service to it.Thanks.


Ok, but it looks like the proxy class (on the client) is returning type
MyWebServiceTest.MyService.GetUserInfoResponseGetU serInfoResult. I bet this
type has a property inside of it with the type User.
--
--------------------------------------------------------------------------------
John Saunders | MVP - Windows Server System - Connected System Developer


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unable to cast type System.Web.UI.Control to System.Web.UI.WebControls.Label and object set to null reference Andy B ASP .Net 2 04-23-2008 04:56 PM
Getting unable to cast error (when same object is referenced in client and web service) Rahul ASP .Net 5 03-01-2008 11:13 PM
Error Rendering Control: unable to cast object of type "System.Web.UI.Page" epatrick@yahoo.com ASP .Net 1 04-12-2007 03:00 PM
Unable to cast object of type 'System.Web.Compilation.BuildResultCompiledAssembly' to type 'System.Web.Util.ITypedWebObjectFactory'. jlecain@free.fr ASP .Net 0 08-03-2006 06:00 PM
Unable to cast object of type 'Oracle.DataAccess.Client.OracleComm =?Utf-8?B?c2Ft?= ASP .Net 0 01-12-2006 03:17 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57