Thursday, July 27, 2006

Correlating using Schemas based on .NET Classes

First of all, we need to create a Biztalk Project wich contains a Property Schema. On this Schema we add the element(s) that we want use for the correlation. For example:


<xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:b=
"http://schemas.microsoft.com/BizTalk/2003" xmlns="http://CorrelatingUsingNetSchemas.Schemas.
MessagePropertySchema
" targetNamespace
="http://CorrelatingUsingNetSchemas.Schemas.
MessagePropertySchema
" xmlns:xs=http://www.w3.org/2001/XMLSchema" >
<xs:annotation>
<xs:appinfo>
<b:schemaInfo schema_type="property" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" />
</xs:appinfo>
</xs:annotation>
<xs:element name="ClientID" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo propertyGuid="1d3dc261-f5ef-4294-a6f3-d7c3f172aea0" propSchFieldBase="MessageDataPropertyBase" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:schema>

Next, we need to add to our solution a .NET Class Library Project. This project must have a reference to Biztalk Project wich contains our Property Schema and a reference to Microsoft.XLANGs.BaseTypes.dll.

Inside this Project we add a class that represents our message schema. This class must be declared as a Serialized Class:

using System;
namespace CorrelatingUsingNetSchemas.NetBasedSchema
{
///
/// My .NET Class based Schema
///

[Serializable ()]
public class SchemaClass
{
}
}


For Correlation, we need to use a promoted property. The promotion of the property must be achieved using a Property Schema, NOT by Distinguished Fields.

To achieve this requisites, first we need to declare a attribute. Type of this attribute must be the type of the Property Schema Field:

// Attribute for correlate
private string _clientID;

For declare the property, we need to declare a Class Property on our Class, that manages the attribute previously declared:

// Property for correlate
public string IDClient
{
get
{
return _clientID;
}
set
{
_clientID = value;
}
}

Now, we only need to say that our property is a Biztalk Property. The type of this property is based on our Property Schema:

// Property for correlate
[Microsoft.XLANGs.BaseTypes.Property (typeof(CorrelatingUsingNetSchemas.Schemas.ClientID))]
public string IDClient
{
get
{
return _clientID;
}
set
{
_clientID = value;
}
}

No comments: