Exposing a class...

T

tascien

Hi guys, I have a class object I want to expose in a webservice
class... How can I make sure that all objects including subclasses are
exposed in WSDL. here is an example:

Public Class Lists '< - class for all lists..

Public Class List ' <- class for a single list contained in
Lists class...

' Member vars...
Public Records() As Record

' Sub classes...
Public Class Record ' <- Class for a single record which is
part of the list...

Public Fields() As Field

Public Class Field ' <- Class for a field. which is
part of the record...
Public Name As String
Public Value As Object
Public Type As String
End Class
End Class
End Class

End Class

Basically, what I want to do, is to be able to create an object like
this in the client...

Dim obj as new Lists.List.Record

or even

Dim obj as new Lists.List.Record.Field

My WebService class could expose it like this...

<WebMethod()> _
Public Function HelloWorld() As Lists '<- just exposing Lists could
trigger sub class exposition...
Return New Lists
End Function

Is that possible? Or do I have to create a function to expose each sub
class?

Tascien
 
K

Kevin Spencer

Anything serializable can be exposed in a Web Service. Some things are
easier to serialize than others. I suggest you read up on Serialization,
specifically XML Serialization.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
We got a sick zebra a hat,
you ultimate tuna.
 
T

tascien

Ok,

thanks but, I thought it would be easy done without learning much about
Serialization...

what usually happens, I create my class in visual studio, inherit a
webservice class, and then when i browse to the webservice asmx, voila,
my class has been Serialized...

The only thing is that complex classes like the ones mentioned about
don't get Serialized correctly. so, I was wondering if there is any
keyword, or something that i need to do to achieve that...

In other words, I rely on visual studio to create my webservice and do
object serialization for me...

T.
 
P

Peter Rilling

You can mark things with the Serializable attribute. There is really
nothing that will ensure that all referenced objects are serializable until
runtime because serialization is not handled by the compiler.

I would learn at least the basics of serialization. One of the problems
with serialization is that if you want to de-serialize it on the other end,
you need to have a copy of the class available. Keep in mind that classes
cannot be miraculously created without a "template". So, if you want to
serialize complex classes that are not part of the framework, both ends need
that class.
 
K

Kevin Spencer

As I mentioned, some things are more easy to serialize than others. The .Net
Framework can serialize some things with no help. For others, it requires
*your* help. That's why I told you to read up on XML Serialization.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
We got a sick zebra a hat,
you ultimate tuna.
 

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

Top