Custom Types

Discussion in 'ASP .Net Web Services' started by Jack, Sep 27, 2006.

  1. Jack

    Jack Guest

    I'm trying to consume a web service that returns some custom types. I'm
    getting the error "[web reference].[object] cannot be converted to [custom
    assembly].[object]". I was able to make it work by overriding some
    definitions in a windows application, but I'm not able to get it to work
    consuming the web service from asp.net.
    Jack, Sep 27, 2006
    #1
    1. Advertising

  2. "Jack" <> wrote in message
    news:...
    > I'm trying to consume a web service that returns some custom types. I'm
    > getting the error "[web reference].[object] cannot be converted to [custom
    > assembly].[object]". I was able to make it work by overriding some
    > definitions in a windows application, but I'm not able to get it to work
    > consuming the web service from asp.net.


    You cannot cast to the custom type in your client. The custom type does not
    exist in your client, only on the server.


    1) The server creates an instance of some custom type
    2) The server sends such an instance in a response
    3) ASP.NET serializes that instance into XML
    4) Your client receives that XML and deserializes it

    The XML is deserialzed into some classes which .NET created for you. They
    were created only as a convenience to you. They keep you from having to
    access web service results as XML.

    These classes are able to deserialize the XML which the web service WSDL
    claims the web service will send.

    If your web reference was created by referencing
    http://host/service.asmx?WSDL, then the WSDL is one generated by ASP.NET. It
    contains XML schema definitions. These are the definitions of the XML into
    which the web service will serialize its results.

    So, there are several layers between you and the custom type the web service
    is returning.

    If you actually need to use the custom type on the client (for instance, if
    you need to call methods on that type), then you need to use .NET Remoting,
    not web services.

    John
    John Saunders, Sep 27, 2006
    #2
    1. Advertising

  3. Jack

    Jack Guest

    I have a windows client where I was able to remove the definitions from the
    reference.vb file created by the web service reference and replace them with
    the custom types by using "imports" statements at the beginning of the file.
    It's a hack, but was recommended in several threads and worked beautifully.

    In asp.net, I'm not seeing the reference.vb file I was hoping for. Is there
    no way with asp.net to wipe the definitions and point them to a different
    location?

    Thanks for the feedback.



    "John Saunders" <john.saunders at trizetto.com> wrote in message
    news:%235G$...
    > "Jack" <> wrote in message
    > news:...
    >> I'm trying to consume a web service that returns some custom types. I'm
    >> getting the error "[web reference].[object] cannot be converted to
    >> [custom assembly].[object]". I was able to make it work by overriding
    >> some definitions in a windows application, but I'm not able to get it to
    >> work consuming the web service from asp.net.

    >
    > You cannot cast to the custom type in your client. The custom type does
    > not exist in your client, only on the server.
    >
    >
    > 1) The server creates an instance of some custom type
    > 2) The server sends such an instance in a response
    > 3) ASP.NET serializes that instance into XML
    > 4) Your client receives that XML and deserializes it
    >
    > The XML is deserialzed into some classes which .NET created for you. They
    > were created only as a convenience to you. They keep you from having to
    > access web service results as XML.
    >
    > These classes are able to deserialize the XML which the web service WSDL
    > claims the web service will send.
    >
    > If your web reference was created by referencing
    > http://host/service.asmx?WSDL, then the WSDL is one generated by ASP.NET.
    > It contains XML schema definitions. These are the definitions of the XML
    > into which the web service will serialize its results.
    >
    > So, there are several layers between you and the custom type the web
    > service is returning.
    >
    > If you actually need to use the custom type on the client (for instance,
    > if you need to call methods on that type), then you need to use .NET
    > Remoting, not web services.
    >
    > John
    >
    >
    >
    Jack, Sep 27, 2006
    #3
  4. "Jack" <> wrote in message
    news:...
    >I have a windows client where I was able to remove the definitions from the
    >reference.vb file created by the web service reference and replace them
    >with the custom types by using "imports" statements at the beginning of the
    >file. It's a hack, but was recommended in several threads and worked
    >beautifully.


    That's not a hack, it's incorrect. I'd love to know what thread recommended
    that.

    The solution is to learn about how web services work. Web services are not
    an object broker or object remoting mechanism. .NET has such a mechanism,
    ..NET Remoting, and it can operate using SOAP over HTTP, just like Web
    Services can.

    John

    BTW, I presume you understand that your Reference.vb is going to be
    overwritten whenever you update your web reference? In fact, since there's a
    big comment at the top telling you not to edit it, you should assume that
    VS.NET will overwrite your changes whenever it feels like doing so.

    Among other things, you should not be surprised if a future version of
    VS.NET doesn't leave you a Refernce.vb file to hack.
    John Saunders, Sep 27, 2006
    #4
  5. Jack

    Jack Guest

    Thanks for the info. If you're interested in reading one of the mentioned
    threads, I'll put a link below. :)

    As you can tell I'm no expert on the subject. I understand what you're
    saying completely. My understanding is that web services exist to port any
    type of data. So if I can serialze custom types and send them out a web
    service, why does it seem to be such a problem consuming them and mapping
    them to anything I want to map them to? It seems like it defeats the entire
    purpose of their existance.

    Oh, and here's a link. Thanks again.

    http://groups.google.com/group/micr...tom type reference.vb&rnum=2#5b96416c0969aefa




    "John Saunders" <john.saunders at trizetto.com> wrote in message
    news:%...
    > "Jack" <> wrote in message
    > news:...
    >>I have a windows client where I was able to remove the definitions from
    >>the reference.vb file created by the web service reference and replace
    >>them with the custom types by using "imports" statements at the beginning
    >>of the file. It's a hack, but was recommended in several threads and
    >>worked beautifully.

    >
    > That's not a hack, it's incorrect. I'd love to know what thread
    > recommended that.
    >
    > The solution is to learn about how web services work. Web services are not
    > an object broker or object remoting mechanism. .NET has such a mechanism,
    > .NET Remoting, and it can operate using SOAP over HTTP, just like Web
    > Services can.
    >
    > John
    >
    > BTW, I presume you understand that your Reference.vb is going to be
    > overwritten whenever you update your web reference? In fact, since there's
    > a big comment at the top telling you not to edit it, you should assume
    > that VS.NET will overwrite your changes whenever it feels like doing so.
    >
    > Among other things, you should not be surprised if a future version of
    > VS.NET doesn't leave you a Refernce.vb file to hack.
    >
    >
    Jack, Sep 27, 2006
    #5
  6. "Jack" <> wrote in message
    news:...
    > Thanks for the info. If you're interested in reading one of the mentioned
    > threads, I'll put a link below. :)
    >
    > As you can tell I'm no expert on the subject. I understand what you're
    > saying completely. My understanding is that web services exist to port
    > any type of data. So if I can serialze custom types and send them out a
    > web service, why does it seem to be such a problem consuming them and
    > mapping them to anything I want to map them to? It seems like it defeats
    > the entire purpose of their existance.


    You can map them to anything you like. But first, you have to define "map".

    If you want to create a custom type and build it into a class library
    assembly, then use the type from that assembly as a response from a web
    service, then put that same exact assembly on the client, then I'm sure
    you'll be able to deserialize into objects of that type.

    But you won't get your auto-generated web service proxy to use your custom
    type. VS.NET has no reason to believe that the type described in the WSDL
    schema has anything to do with your custom type.

    By the time you're using the same .NET assembly on both the client and
    server, you would be better off using .NET remoting. At least that way,
    there will be less temptation to open your web service to Java clients.

    BTW, if you had a Java client, how would you "consume this type"?

    > Oh, and here's a link. Thanks again.
    >
    > http://groups.google.com/group/micr...tom type reference.vb&rnum=2#5b96416c0969aefa



    I just read the post you're referring to, and I don't think the poster was
    talking about editing an auto-generated file like Reference.vb!!! His
    approach would work well for a proxy class created by hand. But you should
    NEVER edit an auto-generated file, as your edits will be lost the next time
    the file is generated.

    John
    John Saunders, Sep 27, 2006
    #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. Sathyaish
    Replies:
    2
    Views:
    585
    Sathyaish
    May 22, 2005
  2. Soren Kuula
    Replies:
    2
    Views:
    559
    Henry S. Thompson
    Dec 1, 2005
  3. Jeremy Cowles

    STD types vs C++ intrinsic types

    Jeremy Cowles, Aug 18, 2003, in forum: C++
    Replies:
    5
    Views:
    1,882
    Bob Jacobs
    Aug 19, 2003
  4. Steve Knight
    Replies:
    2
    Views:
    753
    Steve Knight
    Oct 10, 2003
  5. Manlio Perillo

    missing types in module types?

    Manlio Perillo, May 29, 2004, in forum: Python
    Replies:
    0
    Views:
    349
    Manlio Perillo
    May 29, 2004
Loading...

Share This Page