Custom Types

J

Jack

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.
 
J

John Saunders

Jack said:
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
 
J

Jack

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 said:
Jack said:
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
 
J

John Saunders

Jack said:
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.
 
J

Jack

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
 
J

John Saunders

Jack said:
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"?


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
 

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,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top