Returning complex types

Discussion in 'ASP .Net Web Services' started by Lachlan Gemmell, Jan 20, 2004.

  1. I'm having problems returning complex types from my web service.

    The error I receive is

    "Value of type 'MyApp.localhost.TransferObject' cannot be converted to
    'Transfer.TransferObject'"

    Inside my transfer.dll the following class (simplified here) is declared

    <Serializable()> Public Class ReportTransferObject
    Private m_FileName As String
    Private m_FilePath As String
    Private m_Data() As Byte
    End Class

    My web service imports the transfer.dll and declares the following function

    <WebService(Namespace:="http://blahblahblah.com/")> _
    Public Class MyWebService
    <WebMethod()> Public Function Execute() As Transfer.TransferObject
    Dim theData As Transfer.TransferObject()
    'do stuff
    Return theData
    End Function
    End Class

    The consuming application (MyApp) also imports the transfer.dll and calls
    the web service as follows

    Dim theData as Transfer.TransferObject
    theData = MyWebService.Execute()

    However doing so results in the following error

    "Value of type 'MyApp.localhost.TransferObject' cannot be converted to
    'Transfer.TransferObject'."

    I am unable to cast using either CType or DirectCast without an exception
    being thrown at runtime.

    Why is the web service not transferring the object as being of type
    Transfer.TransferObject? If I try to return a complex type such as DataSet
    it can work that out no problems.

    Regards,

    Lachlan
     
    Lachlan Gemmell, Jan 20, 2004
    #1
    1. Advertising

  2. Lachlan Gemmell

    Jan Tielens Guest

    That's normal behavior. When you are using a web service from your client
    application you've probably added a Web Reference. By doing so VS.NET has
    generated some proxy classes, based on the ReportTransferObject class (and
    probably others).

    So you have to change this:
    > Dim theData as Transfer.TransferObject
    > theData = MyWebService.Execute()


    to

    Dim theData as MyWebService.TransferObject
    theData = MyWebService.Execute()

    --
    Greetz

    Jan Tielens
    ________________________________
    Read my weblog: http://weblogs.asp.net/jan


    "Lachlan Gemmell" <lgemmellATwimsDOTcomDOTau> wrote in message
    news:...
    > I'm having problems returning complex types from my web service.
    >
    > The error I receive is
    >
    > "Value of type 'MyApp.localhost.TransferObject' cannot be converted to
    > 'Transfer.TransferObject'"
    >
    > Inside my transfer.dll the following class (simplified here) is declared
    >
    > <Serializable()> Public Class ReportTransferObject
    > Private m_FileName As String
    > Private m_FilePath As String
    > Private m_Data() As Byte
    > End Class
    >
    > My web service imports the transfer.dll and declares the following

    function
    >
    > <WebService(Namespace:="http://blahblahblah.com/")> _
    > Public Class MyWebService
    > <WebMethod()> Public Function Execute() As Transfer.TransferObject
    > Dim theData As Transfer.TransferObject()
    > 'do stuff
    > Return theData
    > End Function
    > End Class
    >
    > The consuming application (MyApp) also imports the transfer.dll and calls
    > the web service as follows
    >
    > Dim theData as Transfer.TransferObject
    > theData = MyWebService.Execute()
    >
    > However doing so results in the following error
    >
    > "Value of type 'MyApp.localhost.TransferObject' cannot be converted to
    > 'Transfer.TransferObject'."
    >
    > I am unable to cast using either CType or DirectCast without an exception
    > being thrown at runtime.
    >
    > Why is the web service not transferring the object as being of type
    > Transfer.TransferObject? If I try to return a complex type such as DataSet
    > it can work that out no problems.
    >
    > Regards,
    >
    > Lachlan
    >
    >
     
    Jan Tielens, Jan 20, 2004
    #2
    1. Advertising

  3. Thanks for your assistance Jan,

    My problem is that I want to call some methods of TransferObject from my
    client application and I want those calls to be local rather than remote.
    When I do as you suggested in my client application.

    Dim theData as MyWebService.TransferObject
    theData = MyWebService.Execute()

    I cannot then do

    theData.DoStuff()

    There must be a way to do this since if for example my web method were to
    return a System.Data.DataSet instead of a Transfer.TransferObject is it NOT
    necessary to do the following

    Dim theData as MyWebService.DataSet
    theData = MyWebService.Execute()

    Regards,

    Lachlan
     
    Lachlan Gemmell, Jan 20, 2004
    #3
  4. Lachlan Gemmell

    Jan Tielens Guest

    A DataSet is not a "normal" case, in fact (I think) it's the only class with
    this behavior. I tried to emulate it, but I failed. The best solution I came
    up with is to create a wrapper class that encapsulates the webservice proxy
    class and provides some extra functionality.

    I wrote an article about dynamically creating wrapper classes, it doesn't
    solve your problem but maybe you can find some inspiration...
    http://tinyurl.com/2ttfd

    --
    Greetz,
    Jan
    __________________________________
    Read my weblog: http://weblogs.asp.net/jan
    "Lachlan Gemmell" <lgemmellATwimsDOTcomDOTau> schreef in bericht
    news:uC2%...
    > Thanks for your assistance Jan,
    >
    > My problem is that I want to call some methods of TransferObject from my
    > client application and I want those calls to be local rather than remote.
    > When I do as you suggested in my client application.
    >
    > Dim theData as MyWebService.TransferObject
    > theData = MyWebService.Execute()
    >
    > I cannot then do
    >
    > theData.DoStuff()
    >
    > There must be a way to do this since if for example my web method were to
    > return a System.Data.DataSet instead of a Transfer.TransferObject is it

    NOT
    > necessary to do the following
    >
    > Dim theData as MyWebService.DataSet
    > theData = MyWebService.Execute()
    >
    > Regards,
    >
    > Lachlan
    >
    >
     
    Jan Tielens, Jan 20, 2004
    #4
  5. So where does System.Data.DataSet get this extra behaviour from? Is it
    written into the class itself or does the VS web services logic have extra
    provisions for it?

    Lachlan
     
    Lachlan Gemmell, Jan 20, 2004
    #5
  6. Lachlan Gemmell

    Jan Tielens Guest

    I've discussed this some time ago with some MS folks and they told me this
    behavior is really DataSet specific. If you look in the WSDL there is a tag
    that tells .NET that a DataSet is expected, so I assume VS.NET (or the
    wsdl.exe tool) looks for that specific tag.

    --
    Greetz,
    Jan
    __________________________________
    Read my weblog: http://weblogs.asp.net/jan
    "Lachlan Gemmell" <lgemmellATwimsDOTcomDOTau> schreef in bericht
    news:...
    > So where does System.Data.DataSet get this extra behaviour from? Is it
    > written into the class itself or does the VS web services logic have extra
    > provisions for it?
    >
    > Lachlan
    >
    >
     
    Jan Tielens, Jan 20, 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. news.amnet.net.au
    Replies:
    1
    Views:
    582
    =?UTF-8?b?TMSByrtpZSBUZWNoaWU=?=
    Apr 13, 2004
  2. Stanimir Stamenkov
    Replies:
    2
    Views:
    750
    Stanimir Stamenkov
    Oct 25, 2005
  3. Soren Kuula
    Replies:
    2
    Views:
    567
    Henry S. Thompson
    Dec 1, 2005
  4. Robert Mark Bram
    Replies:
    0
    Views:
    687
    Robert Mark Bram
    Feb 4, 2007
  5. Karl

    Returning complex data types

    Karl, Nov 15, 2005, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    114
Loading...

Share This Page