tags:

views:

331

answers:

1

I feel this is a stupid question even before asking, but my brain isn't working too well right now. I have two WCF services "CountryService" and "FloristService".

Now CountryService has the following method:

IList<CountryDTO> GetAllCountries();

Additionally, FloristService has a method:

bool AddFlorist(FloristDTO florist);

All good so far, but the problem is that the FloristDTO references a CountryDTO i.e.

    public  string Address1 { get; set; }
    public  string Address2 { get; set; }
    public  string Address3 { get; set; }
    public  string City { get; set; }
    public  string Postcode { get; set; }
    public  CountryDTO Country { get; set; }
    public  string Name { get; set; }

This is fine, but if I use the service proxy generating util with Visual Stuidos (i.e. Add Reference > Add Service Reference) then I get two versions of CountryDTO are created i.e.FloristService.CountryDTO and CountryService.CountryDTO.

Now I can think of a few ways to overcome this, but nonw of them seem right. I wondered what the "correct" approach to this would be, is there anything funky I can do with the proxy generation tool to make it share common DTOs?

Cheers, Chris

+3  A: 

You can reuse types in svcutil: http://blogs.msdn.com/youssefm/archive/2009/10/09/reusing-types-in-referenced-assemblies-with-svcutil-s-r-switch.aspx

Vitaliy Liptchinsky
Cheers, just what I am after
Owen
Second thoughts, this seems to assume that both the service layer and the consuming layer will have access to the same .dll with the DTO objects in. Now what If I dont have this, and I WANT the svutil generate the proxy classes. BUT I only want them generating once and shared across the services?
Owen
Then you generate the proxy classes once and reuse the generated proxy classes via svcutil /r for subsequent generation of your proxy.
Ronald Wildenberg
Good point :-).
Owen