all groups > dotnet web services > july 2006 >
You're in the

dotnet web services

group:

How to Persist Custom Class to Web Client?


How to Persist Custom Class to Web Client? samtilden NO[at]SPAM gmail.com
7/28/2006 8:06:40 AM
dotnet web services:
I made my own class, MyCompany.MyClass and I want to send one object of
this class from my webservice to the client.

On the client side, when I Update Web Reference, the object is known as
ProjectName.localhost.MyClass and not MyCompany.MyClass and the C# code
cannot cast from one to the other.

I can manually go into Reference.cs and tell the client side to expect
MyCompany.MyClass, but each time I do an Update Web Reference, my
manual change is wiped out (as expected).

Is there some attribute, flag, configuration setting I need to set in
order for the client to expect the correct class?

Thanks.
Re: How to Persist Custom Class to Web Client? Pablo Cibraro [MVP]
7/31/2006 10:12:22 AM
No, VS or the wsdl.exe tool always create a new class from the type exposed
in the WSDL. (The class used as parameter in the web service, in your case,
MyCompany.MyClass). That happens because the web service can be implemented
in any platform, not only .NET.
Anyway, both classes represent the same XML, so if you use the generated
class in the client, the service will receive a MyCompany.MyClass instance.
(.NET performs the XML serialization and derialization for you, that process
is completely transparent).
In that way, the client application and the web service are loose-coupled by
types.
Your client application should use that generated class and not the original
one (MyCompany.MyClass) in order to consume any web service with the same
WSDL.

Regards,
Pablo Cibraro
http://weblogs.asp.net/cibrax


[quoted text, click to view]

AddThis Social Bookmark Button