Search code examples
wcfrestnamespacesversiondatacontract

WCF Rest DataContract and ServiceContract Versioning


I've spend many hours reading about DataContact and ServiceContract versioning techniques:

Best practices for API versioning?

My take away from all of these are the following

1) REST Uri's needs to be versioned.

[http://example.com/v1/car]
[http://example.com/v2/car]

2) Each REST resource operation that involves XML needs to contain XML namespace

<SampleItemCol xmlns="http://api.sample.com/2011/04/05">
  <Items>
    <SampleItem xmlns="http://api.sample.com/2011/04/01">
      <Test xmlns="http://schemas.datacontract.org/2004/07/WcfRestService2">String content</Test>
      <Id>2147483647</Id>
      <StringValue>String content</StringValue>
      <TestGuid>1627aea5-8e0a-4371-9022-9b504344e724</TestGuid>
    </SampleItem>
    <SampleItem xmlns="http://api.sample.com/2011/04/01">
      <Test xmlns="http://schemas.datacontract.org/2004/07/WcfRestService2">String content</Test>
      <Id>2147483647</Id>
      <StringValue>String content</StringValue>
      <TestGuid>1627aea5-8e0a-4371-9022-9b504344e724</TestGuid>
    </SampleItem>
  </Items>
</SampleItemCol>

So here are my questions:

1) Assuming there are hundreds of data contracts and many ServiceContracts, what would be the best class library structure to maintain different versions and namespaces?

2) If Uri's are versionined, do we even need to specify namespace for ServiceContracts?

3) Suppose there are 50 data contracts. All of them have namespace http://example.com/2011/04/01/. If 10 of these change and new namespace is created, http://example.com/2011/04/05/. Should the other 40 be copied to new namespace as well?

My biggest concern about REST namespaces and URI versions is the maintainability and class redundancy.

Thanks in advance for you suggestions and answers!


Solution

  • I went down this route with versioned service contracts and datacontracts. It was a nightmare. The worst/best part is that if you take advantage of hypermedia you really do not need to version your API at all.

    If you read shonzilla's post again you will see that he is really not advocating putting versions in the URI. He shows a way to do it by using redirects, but most of his reasoning advocates against it. My previous answer to this question is here

    It is also worth reading Peter Williams post on the subject.

    I use XML almost exclusively for the format of my media types and I don't use namespaces at all.