Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share DTO objects between WCF services

Tags:

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

like image 984
Owen Avatar asked Oct 28 '09 13:10

Owen


1 Answers

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

like image 197
Vitaliy Liptchinsky Avatar answered Oct 12 '22 08:10

Vitaliy Liptchinsky