I have a simple question. I am using WCF to create web services. I have created all the services without filling the operation bodies. Now I have the wsdl files auto-generated from the service contracts. Is this approach "Contract First", if I am coding the operation implementations later?
2 Answers
Yes, because you're defining the contract between you and anyone consuming your API first. Usually (but not always) the contract/API is defined via an interface.
Edit: As Namphibian said in the comments, if you're building web services contract first, then you would want to define your WSDL first and generate the code from there. My answer assumed you wanted to develop a .NET API contract first and that you were going to expose it as a web service after the fact.
Second edit: I wanted to add that SOA principles themselves have nothing to do with web services. You can build services that are only exposed via their codified API.

- 388
- 2
- 9
-
yes, I have used interface for defining the contracts. Is it the right approach? – Nadia Nahar Jun 14 '15 at 07:16
-
@JimSimon your approach is based on some good principles. Always use interfaces. However this is not quiet contract first approach which requires the WSDL to be created and then implemented. I downvoted by accident and now my vote is locked in. Could you edit the answer a little so I can upvote. I do apologize this was not intended. It is just early monday morning and I was busy with first cup of coffee. – Namphibian Jun 14 '15 at 22:06
-
Edited to include your feedback. :) – Jim Simon Jun 14 '15 at 22:11
This is not quite correct. You are simulating contract first but you are still relying on the .Net framework to generate the WSDL. In contract first/WSDL first coding(top down) approach you author a WSDL file with a tool such as XML Spy etc. Then you generate the code from the WSDL. In your approach you are creating a WSDL from interfaces.
Using interfaces is the most successful way of doing this type of development however you are still doing the code first. Let me clarify that with an example. Typically in a SOA architecture developers follow the WSDL first approach. In the WSDL first approach you would typically submit your WSDL file for review by a SOA governance body in your company. This WSDL will then be measured against SOA governance policies to see if it fits. Once approved only then would code artifacts get generated.
What you are doing is not wrong but it is NOT contract first approach.

- 12,046
- 7
- 46
- 76
-
So do you mean that, it will be a contract first approach only if I write the WSDL file by myself? – Nadia Nahar Jun 15 '15 at 13:03
-
@NadiaNahar academically speaking yes. Remember a web-service is a contract described by using a WSDL. This is very much like a interface in Java or .Net. The interface however does not specify the implementation. Thus with a contract first approach the intrface(WSDL) can be implemented in any technology(.Net/Java/Delphi/PHP). Your approach is based on very solid foundations. Always use interfaces and not implementations. This leads to loose coupling and more agile development. – Namphibian Jun 15 '15 at 22:11