467,877 Members | 1,243 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,877 developers. It's quick & easy.

Name conflict due to generic types and nested classes in web services[long]


I have a simple 2-tiers (client+database) application with simple
Domain Model objects The Data Access Layer is abstracted via Data
Mappers which use Data Transfer Objects to communicate with the Domain
Model objects. My Domain Model objects are declared this way :

public class City /* Inheritance removed for brevity...*/
private string _Name;
private string _ZipCode;

public struct DataTransferObject
public string Name;
public string ZipCode;

Constructors, methods, properties removed for brevity...

I have a generic class DomainModelDto<TDtocontains the actual data
that is transfered between layers via

Everything is fine so far. The problem occurs when we try to create a
3-tiers (client+web services+database) application. We just want to
create new Data Mappers that will communicate to Web Services, instead
of a database. The Web Services will use the previous Data Mappers to
communicate with the database. Lot of code reuse : great !
So I create web services functions such as

public DomainModelDto<City.DataTransferObjectCityFindAll( )
{ /* ... */ }

That will work until I had another function based on another Domain
Model object (say Contact) :

public DomainModelDto<Contact.DataTransferObjectContactFi ndAll()
{ /* ... */ }

As both DomainModelDto<City.DataTransferObjectand
DomainModelDto<Contact.DataTransferObjectare serialized with the name
"DomainModelDtoOfDataTransferObject", they conflict and the web project
will not compile.

So far, the only solution I have found to this problem is to rename the
DataTransferObject structures so that they have unique names. But I
would be much more satisfied with another solution.

I have tried :
* Add [return: XmlRoot("....")] attributes to the web services methods,
but that will not change anything.
* Add [XmlRoot("...")] and [SoapType(...)] attributes to the nested
DataTransferObject classes : wasted time.
* Have DomainModelDto implement IXmlSerializable, and specifiy the
XmlSchemaProvider attribute. But then, if I know how to serialize my
generic Dto (City for instance) with a XmlSerializer, I do not know how
to get the schema for the type (the only way I have found is to use
xsd.exe, which is ... not a way !).

Thanks for reading this far, any help appreciated.

Aug 30 '06 #1
  • viewed: 1176

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Bryan Olson | last post: by
16 posts views Thread by tshad | last post: by
21 posts views Thread by Charles Sullivan | last post: by
6 posts views Thread by karthikbalaguru | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.