Problem sharing custom data types across web services

Hi all,

I'm having a bit of trouble sharing some user defined objects across multiple web services. FYI I'm using visual studio team system, and adding my web services using the application designer, so most of the web service code is auto generated.

Alright, this is the situation. I have a class library in which my custom data types are defined, lets say the namespace for this class library is clibrary, and there is a class representing a custom object within this library called CustomObject.

I also have two web services, service 1 and service 2, with different namespaces ws1 for service1 and ws2 for service2. Both web services have a reference to the library containing my custom object.

Service1 has a web method GetCustomObject which returns clibrary.CustomObject as it's type.

Service2 has a reference to the web service Service1 and a method ConsumeGetCustomObject. Within this method an object of type clibrary.CustomObject is defined, and I attempt to assign it to the result of a call to Service1.GetCustomObject. However I will get an error in the form of ws1.CustomObject (ws1 being the namespace of the Service1) cannot be converted to type clibrary.CustomLibrary.

Any ideas as to why I get this error. It seems to me that service2 learns of the CustomObject through it's reference to service1, but why does service1 append it's namespace to CustomObject. I've been researching this problem to no avail and I'm convinced theres something simple I'm missing out. Please if you have any ideas or direction you can point me in let me know.

[1608 byte] By [vakman] at [2007-12-22]
# 1
When using webservices the webreference that consumes the webservice generates its own proxy classes based upon your custom classes, ie clibrary. You have two choices. Instead of using your custom classes within your application you can import the webreference proxy classes and use them. This limits the usability as the proxy classes only expose public properties as public fields and you will lose any methods within your custom classes. The second option is to remove the proxy classes generated by the visual studio tool and import the dlls which contain your custom classes, this is done in the web reference's 'Reference.vb' file. FYI - everytime you update your webreference you have to remove the proxy classes and import your namespaces again because the file is regenerated, this can get to be pretty tedious. Hope that helps.
EvanCarrish at 2007-8-30 > top of Msdn Tech,.NET Development,ASMX Web Services and XML Serialization...
# 2

On the server side , you can serialize your custom classes into string/bytes off hand (using binary formatter,Xmlserialzer etc..),essentaily web methods will take string/bytes as parameter.Then on the client side you can deserialize the string back to original objects.Hope this helps

Chigurala at 2007-8-30 > top of Msdn Tech,.NET Development,ASMX Web Services and XML Serialization...
# 3
Evan Carrish wrote:
The second option is to remove the proxy classes generated by the visual studio tool and import the dlls which contain your custom classes, this is done in the web reference's 'Reference.vb' file. FYI - everytime you update your webreference you have to remove the proxy classes and import your namespaces again because the file is regenerated, this can get to be pretty tedious. Hope that helps.

I use the second option and it works fine, although it's a bit annoying if you need to update your WS often. Simply delete all the custom classes created by Visual Studio and import your custom types in Reference.vb/cs.

See this article for more detailed information.

kimphamg at 2007-8-30 > top of Msdn Tech,.NET Development,ASMX Web Services and XML Serialization...
# 4

A Schema Importer Extension can be used to customize the proxy generation.... specially it allows you to add custom references to other projects using CodeDOM.

Please take a look at this post in where I explain how to use it:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=737363&SiteID=1

Rgds

Rodrigo

rfreire at 2007-8-30 > top of Msdn Tech,.NET Development,ASMX Web Services and XML Serialization...

.NET Development

Site Classified