Convention, configuration and WCF

Convention is something that’s fairly lacking in WCF.  Here’s what I’d like to do:

[ServiceContract]
public interface ICustomerSearch
{
    Customer FindCustomerByName(string name);
}

public class Customer
{
    public string Name { get; set; }
    public CustomerType Type { get; set; }
}

public enum CustomerType
{
    Good,
    Canadian
}

I understand maybe just that one attribute.  Here’s what I’m forced to do:

[ServiceContract]
public interface ICustomerSearch
{
    [OperationContract]
    Customer FindCustomerByName(string name);
}

[DataContract]
public class Customer
{
    [DataMember]
    public string Name { get; set; }
    [DataMember]
    public CustomerType Type { get; set; }
}

public enum CustomerType
{
    Good,
    Canadian
}

All those noisy attributes, none adding any information nor functionality.  What’s consistently bothered me the most is how much configuration is necessary to get straightforward scenarios working.  I’m tired of opting-in to every single piece of information on the contract side.  I want to point to an interface, and just let the framework figure out the rest.

On the plus side, lots of vendors recognized this and created products on top of WCF to make it usable.  Good for them.

Related Articles:

Post Footer automatically generated by Add Post Footer Plugin for wordpress.

About Jimmy Bogard

I'm a technical architect with Headspring in Austin, TX. I focus on DDD, distributed systems, and any other acronym-centric design/architecture/methodology. I created AutoMapper and am a co-author of the ASP.NET MVC in Action books.
This entry was posted in WCF. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • http://www.twitter.com/MotoWilliams MotoWilliams

    Will this be improved, in your eyes, somewhat with the 3.5 SP1 (after MS Fixes the SP) changes to WCF in that [DataContract] / [DataMember]?

  • http://www.twitter.com/MotoWilliams MotoWilliams

    I need to proof read – Does this get better with the SP in that some of those attribues aren’t needed anymore?

  • http://www.bluespire.com/blogs Rob

    I Believe that sp1 enables you to serialize objects without DataContract/DataMember. But, I don’t think you can remove the ServiceContract/OperationContract. I haven’t confirmed yet.

  • http://jimmybogard.lostechies.com Jimmy Bogard

    @Rob, Moto

    Ah thanks, I’ll check that out. The WCF improvements seem to have been glossed over in many announcements.

    Though with Ayende’s recent troubles, I’m not sure when I’ll upgrade.

  • http://flux88.com Ben Scheirman

    Wow, I have that same enumeration in many of MY projects!

  • Jeremy Gray

    @Jimmy and Ben – Consider yourselves very lucky to only have customers that are either good or awesome. ;)

  • http://hex.lostechies.com erichexter

    3.5 sp1 really covers most of your pain, here. They have clearly stated the support for POCO with wcf in the service pack. I think it is time for Rhino Mocks to not worry about being all things to all languages and just roll in the fix for c#….