-4

I have xsd as a contract for my web service. The web service is implemented as web api, I am looking for a tool that generates web api model from xsd. This tool should add atributes from the xsd so asp.Net will know to validate the request.

Daniel Rapaport
  • 375
  • 2
  • 18
  • 1
    Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, [describe the problem](http://meta.stackoverflow.com/questions/254393/what-exactly-is-a-recommendation-question) and what has been done so far to solve it. – Darin Dimitrov Feb 04 '16 at 21:09
  • not sure how can I ask it diffrently... I am faceing so difculties translating xsd to web api model. and i asked if there is an automation I can use? the xsd is long and complex. – Daniel Rapaport Feb 04 '16 at 21:49
  • Depending on what you mean with "automation for translating a XSD into a Web API model". The XSD will contain type definitions only, not a Web API. You can use "XSD.EXE" from the command prompt on the .XSD file to generate the C# classes. – Marvin Smit Feb 07 '16 at 10:20
  • xsd.exe will not create web api model – Daniel Rapaport Feb 07 '16 at 16:52
  • 1
    T4. You have to write the template. At the end you need to make some work here - no magic bullet. – TomTom Feb 07 '16 at 17:03
  • Tool recommendation questions are off-topic here and placing a bounty on the question will not save it from being closed. – Mathias Müller Feb 11 '16 at 19:33

1 Answers1

0

The way to do this is to use the XSD.EXE to generate the C# classes (POCO's) you need. Then use scaffolding with T4 templates to generate the API code.

I would start by looking at ScottGu's blog: http://weblogs.asp.net/scottgu/asp-net-mvc-1-0-release-candidate-now-available

It's a bit old, but still relvant.

What I would do is create custom scaffolders for creating the webAPI controllers, here is a description: https://www.credera.com/blog/technology-insights/microsoft-solutions/create-custom-scaffold-templates-asp-net-mvc/

Short version: %programfiles%\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding\Templates contains the original templates. Copy these to your project under the folder \CodeTemplates. Modify them as needed (ex change : Controller to ApiController)

The convention is that the scaffolding engine uses the templates in the CodeTemplates project folder, if one exists, instead of the global templates.

devzero
  • 2,510
  • 4
  • 35
  • 55