casting WebService TreeNode to C# Client App TN

D

djp

Hi
I add web reference to my C# client app and call web method that returns
TreeNode.
I tried to cast WebService TreeNode to Windows Forms TreeNode, but without
any effect.
Any ideas?

Thanks
PK
 
B

Ben Rush

When you utilize a web service to return an existing type, the service
framework will create a new type for its purposes; it does this because not
everything that can be found in a .Net "type" makes sense in a webservice
"type". What you are more than likely encountering is a casting issue
because the type generated by the service framework is different than the
windows forms treenode. This is a basic/fundamental issue of typing.

If you absolutely have to pass a treenode instance from a web service, you
could always use serialization and return a byte stream; I have never done
this but I can't see why it wouldn't work.

.....not sure of your ultimate goal here, though.
 
D

djp

i am not sure if sending byte stream is good idea. Concept of WebServices is
to pass objects.
When i create webservice treenode and windows.forms treenode i can see that
they are identical
iam almost sure there is a way to cast one to another, however i cannot find
solution...
 
B

Ben Rush

The members, methods, properties, etc. can all be identical but it can still
be a different data type as far as the runtime is concerned. How are you
seeing that they are identical? Type identity is more in-depth than
identical members. If you cannot cast one to another, then the types are
different.

You can pass anything you want back from a web service, it doesn't have to
be an object.
 

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