Orchestration中验证XML Schema Message的方法

示例代码:
public static void ValidateDocument( XmlDocument businessDocument, string schemaStrongName )
{
  // Constants
  const int PARTS_IN_SCHEMA_STRONG_NAME = 2;
  const int PART_CLASS_NAME = 0;
  const int PART_QUALIFIED_ASSEMBLY_NAME = 1;

  // Parse schema strong name
  string[] assemblyNameParts = schemaStrongName.Split( new char[] { `,` }, PARTS_IN_SCHEMA_STRONG_NAME );
  string className = assemblyNameParts[PART_CLASS_NAME].Trim();
  string fullyQualifiedAssemblyName = assemblyNameParts[PART_QUALIFIED_ASSEMBLY_NAME].Trim();

  // Load assembly
  Assembly schemaAssembly = Assembly.Load( fullyQualifiedAssemblyName );

  // Create instance of the BTS schema in order to get to the actual schemas
  Type schemaType = schemaAssembly.GetType( className );
  Microsoft.XLANGs.BaseTypes.SchemaBase btsSchemaCollection = ( Microsoft.XLANGs.BaseTypes.SchemaBase )Activator.CreateInstance( schemaType );

  // Set up XML validating reader and validate document
  XmlParserContext parserContext = new XmlParserContext( null, null, ", XmlSpace.None );
  XmlValidatingReader reader = new XmlValidatingReader( businessDocument.OuterXml, XmlNodeType.Document, parserContext );
  reader.ValidationType = ValidationType.Schema;
  reader.Schemas.Add( btsSchemaCollection.SchemaCollection );
  while( reader.Read() ) {}
}

在Expression Shape中调用:ValidateDocument( myBtsMessage, myBtsMessage( BTS.SchemaStrongName ) );

From: http://www.topxml.com/rbnews/XmlDocument/re-22687_Cool-XSD-Validation-Function-for-Orchestration.aspx

你可能感兴趣的:(message)