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

Discussion in 'ASP .Net Web Services' started by Rahul, Jan 14, 2008.

  1. Rahul

    Rahul Guest

    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 !!!!!
     
    Rahul, Jan 14, 2008
    #1
    1. Advertising

  2. "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
     
    John Saunders [MVP], Jan 14, 2008
    #2
    1. Advertising

  3. Rahul

    william Guest

    Re: Getting unable to cast error (when same object is referenced i

    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.GetUserInfoResponseGetUserInfoResult 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
    >
    >
    >
     
    william, Feb 27, 2008
    #3
  4. Re: Getting unable to cast error (when same object is referenced i

    "william" <> wrote in message
    news:...
    > 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.GetUserInfoResponseGetUserInfoResult 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
     
    John Saunders [MVP], Feb 28, 2008
    #4
  5. Rahul

    william Guest

    Re: Getting unable to cast error (when same object is referenced i

    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:...
    > > 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.GetUserInfoResponseGetUserInfoResult 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
    >
    >
    >
     
    william, Feb 29, 2008
    #5
  6. Re: Getting unable to cast error (when same object is referenced i

    "william" <> wrote in message
    news:...
    > 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.GetUserInfoResponseGetUserInfoResult. I bet this
    type has a property inside of it with the type User.
    --
    --------------------------------------------------------------------------------
    John Saunders | MVP - Windows Server System - Connected System Developer
     
    John Saunders [MVP], Mar 1, 2008
    #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?c2Ft?=
    Replies:
    0
    Views:
    1,755
    =?Utf-8?B?c2Ft?=
    Jan 12, 2006
  2. Replies:
    1
    Views:
    640
  3. Rahul
    Replies:
    5
    Views:
    414
    John Saunders [MVP]
    Mar 1, 2008
  4. Andy B
    Replies:
    2
    Views:
    3,173
    Andy B
    Apr 23, 2008
  5. Ray Stevens
    Replies:
    5
    Views:
    275
    Josh Twist
    Feb 4, 2006
Loading...

Share This Page