I’m pretty excited to the announce that I’ve manage to crash three pretty well known Internet sites. I didn’t attempt to hack them nor did I play script kiddie and go for a denial of service attack. I simply used the sites as they were intended. The latest victim of my legendary QA skills is Hitachi. I had a couple bad SCSI drives that I was checking the warranty on and I end up with 500 error.

This comes after I helped Hertz and ATARI with their testing activities.
-CP
Schema Importer Extensions
Schema Importer Extensions are a little known mechanism to ease web services development when your team is simultaneously responsible for constructing a service consumer/requestor of those services. Microsoft does not go out of its way to promote their existence because on the surface the extensions seem counter to the party line regarding SOA. Specifically, if you are familiar with the four tenets of SOA, tenet 3 states that services share schema and contract, not class. So, why should you consider using Schema Importer Extensions?
I will use a trivial example to illustrate the point. The first service, ConsultantService, provides functionality to manage consultants. The second service, ProjectService, provides functionality to manage projects. ConsultantService exposes an operation to retrieve information about an individual consultant and the ProjectService exposes an operation to retrieve a list of consultants staffed on a given project. The development team has decided to use the same Consultant class in both services since they are both interacting with the same logical domain object.
Out of the box experience with Add Web Reference
This scenario was your only option when using Microsoft’s tools prior to the .NET 2.0 Framework. This is still true for developers that dropped to the command line and tried to find a solution using the WSDL.EXE tool. The result is that for each proxy class generated a unique Consultant class will also be generated. These Consultant classes will be treated as distinct CLR types and not compatible even though they have the same signature.

Obviously, this can lead to a lot of confusion, extra code, and frustration over the Microsoft Web Services stack. I’ve personally seen this behavior stump quite a few development teams and I’ve seen the crazy mapping code that goes along with it as a workaround. Architects and developers that understand what is happening under the hood have written custom tools and even hand-edited the generated files to reach outcomes described in the subsequent scenarios.
Using WSDL.EXE with the /sharetypes Switch
This scenario is a good option when your development team is solely responsible for the consumer. By specifying the /sharetypes on the command line or using a parameters file like the one below you inform WSDL.EXE that you wish the tool to take two more WSDL documents and generate the proxies in a single file and create a single instance of types that are shared across the services described in the documents.
1: <wsdlParameters xmlns="http://microsoft.com/webReference/">
2: <nologo>true</nologo>
3: <parsableerrors>true</parsableerrors>
4: <sharetypes>true</sharetypes>
5: </wsdlParameters>
The result is that there will be distinct CLR types; one on the server (if it is a .NET service) and one on the client. However, now client developers are free to use the same Consultant instance with multiple proxies and have a more expected development experience.

There are a few limitations with this approach. First of all, the client-side representation of the Consultant object may not be ideal. For example, a Project object may contain a list of staffed consultants. By default, WSDL.exe will represent this as a simple array of Consultant instead of a more advanced structure like a List<Consultant>. This can be frustrating where the same team is responsible for both sides of the wire because on the server side they could program against these more advanced structures if they didn’t start with an XSD document to generate the classes.
Using a Schema Importer Extension
This scenario is a good option, as I mentioned at the beginning, when your development team is responsible for both the services and the service consumer. The result is that the service developer and client developer are working with the same CLR type meaning any advanced structures may be leveraged on both sides of the wire.

The real value here is that you can achieve this through Add Web Reference in the IDE without requiring your developers to drop to the command line to use the WSDL.EXE tool. The code for this is actually quite simple.
1: public class InsightSchemaImporterExtension : SchemaImporterExtension
2: { 3: private const string _messagesNamespace = "FloridaTechnology.Insight.Contracts.Messages";
4:
5: public override string ImportSchemaType(string name, string ns, XmlSchemaObject context, XmlSchemas schemas,
6: XmlSchemaImporter importer, CodeCompileUnit compileUnit,
7: CodeNamespace mainNamespace, CodeGenerationOptions options,
8: CodeDomProvider codeProvider)
9: { 10: if (ns == Schemas.Messages)
11: { 12: mainNamespace.Imports.Add(new CodeNamespaceImport(_messagesNamespace));
13: return _messagesNamespace + "." + name;
14: }
15: else
16: { 17: return
18: base.ImportSchemaType(name, ns, context, schemas, importer, compileUnit, mainNamespace, options,
19: codeProvider);
20: }
21: }
22: }
You create a class that derives from SchemaImporterExtension and overrides the ImportSchemaType method. Within that method you look for the XML namespace for which you already have a .NET assembly created and tell the schema importer the name of the existing type and your done. From there you need to drop your assembly in the GAC and modify the MACHINE.CONFIG file. At the bottom you need to add a “system.xml.serialization” element and child element by the name of “schemaImporterExtensions”. Here is where you register all your schema importer extensions.
1: <add name="InsightSchemaImporterExtension"
2: type="FloridaTechnology.Insight.Tools.InsightSchemaImporterExtension, 3: FloridaTechnology.Insight.Tools, Version=1.0.0.0,
4: Culture=neutral,
5: PublicKeyToken=b14049c152a3ca41"
3: FloridaTechnology.Insight.Tools, Version=1.0.0.0,
4: Culture=neutral,
5: PublicKeyToken=b14049c152a3ca41"
6: />
Alternatively, if you want to use the command line and specify a parameters file you can use something like the following:
1: <wsdlParameters xmlns="http://microsoft.com/webReference/">
2: <nologo>true</nologo>
3: <parsableerrors>true</parsableerrors>
4: <sharetypes>true</sharetypes>
5: <documents>
6: <document>http://www.contoso.com/service.asmx?WSDL</document>
7: </documents>
8: <webReferenceOptions>
9: <verbose>false</verbose>
10: <codeGenerationOptions>properties newAsync enableDataBinding</codeGenerationOptions>
11: <schemaImporterExtension>
12: <type>MyNamespace.MyCustomImporterExtension,ExtensionLibrary</type>
13: </schemaImporterExtensions>
14: <style>client</style>
15: </webReferenceOptions>
16: </wsdlParameters>
Conclusion
It is important to note, that using Schema Import Extensions does not reduce the interoperability of the your services or the purity of your SOA based application. In fact, it does not modify any server behavior. Use of these extensions only affect the behavior when generating proxy classes and is only relevant when you have direct access to the same assemblies being used to create the services on the server.
-CP
Hopefully the released versions resolve this issue but the Medieval II Total War Demo is unplayable on Vista. On RC1 the video options had to be on the lowest setting and on RC2 the screen flickered wildly. It is not the hardware, because I have a fully loaded Tecra M5 Dual Core 2.16, 2GB RAM, 7200 100GB SATA HD, and 128MB Nvidia card that runs Aero just fine. The demo plays great on XP sitting on much less hardware.
-CP
There are quite a few posts I need to publish after a 2 month drought. While many things have demanded my time recently, launching a new practice and ensuring the success of our partners tops the list. However, I’m pleased to say that we finally got enough breathing room to get a more established web presence. So, please take a look at the new FloridaTechnology.com and see what we are all about. We don’t have a recruiting section up yet, but if you want get your resume into the pipeline go ahead and hit the contact link on the menu.
-CP