Returning complex types

L

Lachlan Gemmell

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
 
J

Jan Tielens

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
 
L

Lachlan Gemmell

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
 
J

Jan Tielens

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
 
L

Lachlan Gemmell

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
 
J

Jan Tielens

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.
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top