The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Today and tomorrow: Will Indigo heal...? Powerful object model for contract-first glue

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Christian Weyer

Posts: 616
Nickname: cweyer
Registered: Sep, 2003

Christian Weyer is an independent Microsoft MSDN Regional Director and expert for Web services.
Today and tomorrow: Will Indigo heal...? Powerful object model for contract-first glue Posted: Feb 14, 2005 7:27 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Christian Weyer.
Original Post: Today and tomorrow: Will Indigo heal...? Powerful object model for contract-first glue
Feed Title: Christian Weyer: Web Services & .NET
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/cweyer/Rss.aspx
Feed Description: Philosophizing about and criticizing the brave new world ...
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Christian Weyer
Latest Posts From Christian Weyer: Web Services & .NET

Advertisement

So, the first stormy Indigo days are gone... Just want make my point clear: Indigo rocks, I love Indigo.

Anyway, with the current development of this 'contract' discussion, I thought I might leave the Hello World samples (like "Basic Hello World', 'Queued Hello World' over MSMQ, and 'Hello World v.Duplex') to my Indigo friends.

What I want to deal with here today is how a developer who believes in the very one approach to service and Web service design, can also use and embrace it with Indigo - or at least thoroughly understand any implications.

Until now, I have never written much about code generation from XSD and WSDL for the ASMX (or WSE) stacks. Maybe this would make a nice in-depth hardcore article for MSDN. But now with the rise of Indigo, I think people should see the light of the extremely clever and powerful Indigo platform. Indigo has not only the overall cool and sexy ServiceModel programming model which gets manifested at the surface at least by a number of .NET attributes. No.

Indigo also has (although currently still a bit rough) a powerful means to transform your XSD and WSDL and Policy metadata into a CLS-compliant representation. Yes, sure. There is a command line tool called svcutil.exe. But I intend to dive a bit deeper and show how the guts of such a tool work.
Using the following code you can easily imagine how you can build your own tools (if you are an alien called 'plumber' or 'tool vendor') in order to provide some functionality for schema-based contract-first design and development which serves Indigo as the runtime. Obviously, this is nothing more than some demo code.

 public static void ImportMetadataAndGenerateCode()
{
   WsdlImporter importer = new WsdlImporter();

   // Load metadata documents from current directory
   // XSDs
   foreach(string xsdFile in Directory.GetFiles(".", "*.xsd", SearchOption.TopDirectoryOnly))
   {
     importer.XmlSchemas.Add(System.Xml.Schema.XmlSchema.Read(File.OpenRead(xsdFile), null));
   }

   // WSDLs
   foreach(string wsdlFile in Directory.GetFiles(".", "*.wsdl", SearchOption.TopDirectoryOnly))
   {
     importer.WsdlDocuments.Add(System.Web.Services.Description.
       ServiceDescription.Read(File.OpenRead(wsdlFile)));
   }

   // Policies
   foreach (string policyFile in Directory.GetFiles(".", "*.wsp", SearchOption.TopDirectoryOnly))
   {
     XmlDocument doc = new XmlDocument();
     doc.Load(File.OpenRead(policyFile));
     importer.Policies.Add(doc.DocumentElement);
   }

   ServiceContractGenerator generator = new ServiceContractGenerator();

   // Generate code from contracts
   foreach (ContractDescription contract in xlator.ImportAllContracts())
   {
     generator.GenerateServiceContractType(contract);
   }

   // Here we have the abstract CLS CodeDom in 'our hands'... (in generator.TargetCompileUnit)
   using (StreamWriter writer = new StreamWriter(File.Create("firststeps.cs")))
   {
     new Microsoft.CSharp.CSharpCodeProvider().GenerateCodeFromCompileUnit(
       generator.TargetCompileUnit, writer,
       new System.CodeDom.Compiler.CodeGeneratorOptions());
   }
}

Compared to today's available APIs when it comes to code generation based on metadata, the new Indigo API is much more powerful, feature-rich, and - most important to me - elegant to program. Any of them, whether old or new, are spitting out a CodeDom tree representation. This is perfect for applying code enhancements through a decorator pattern-oriented approach. Once you have the CodeDom in place, you can literally do anything with it.
Note: AFAIK, WSE has no official, 'native' approach to get at the code/CodeDom from any XSD and/or WSDL. At least, I could not manage to hack it up in a reasonable amount of time.

Voila. This is the very first rough starting point for adding Indigo code-gen support to tools like WSCF. Sorry for no square brackets being present in above's snippet ;)

So, this is just one small piece of the big, big world of Indigo. Maybe next time, we will dive again into the deep areas of distributed applications programmer's new baby... there is enough to cover for everybody.

Read: Today and tomorrow: Will Indigo heal...? Powerful object model for contract-first glue

Topic: My Picks for TechEd 2005 Previous Topic   Next Topic Topic: Heather Very Sick All Week

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use