Links for 2007-04-16 [del.icio.us]
- GotDotNet User Sample: Biztalk Scheduled Task Adapter
Special-adapter f%u00f6r scheduled tasks
This entry describes two helper methods to interact with messages in a BizTalk orchestration. The first helper methods will return the string representation of a BizTalk message. The methods are as below: /// <summary> /// Pass in a BizTalk Message…(read more)
So there’s a new website/newsletter for BizTalk addicts created by some great Microsoft Technology Specialists. Go to BizTalk Hotrod and check out the first issue. The newsletter is surprisingly well put together, and was actually a quite educational read.
I must admit, though, when I got an email saying “Check out BizTalkHotRod.com”, I was […]
You can find all the information you need to configure WCF Service in BizTalk Server 2006 R2 WCF Adapter from Sonu Arora’s blog along with documentation.
For those of you, who want to get a better understanding on what are channels, bindings, etc in WCF Service,check the following link to understand them from Clemens Vasters (WCF […]
Because there is so much written about this pipeline component, I would list some things it does (refering to here and here):
Now the question is why/where would you use it?
I am involved in a project that the use #3 is the reason why I needed to use it. We are creating a standard message, and the process to import the data into the application is complete, the only problem is there is no routing information in the data, where it came from. It only has data about the patient, not who sent the data. What I really needed to do is attach wrapper data to the original message.
The Framework Pipeline component is the perfect solution. Some things that are required, but not documented are the following properties (in bold):
IsReliable
PassAckThrough
eps_to_address
eps_to_address_type
eps_from_address
eps_from_address_type
prop_identity
prop_sentAt
prop_topic
svc_deliveryRctRqt_sendTo_address
svc_deliveryRctRqt_sendTo_address_type
svc_deliveryRctRqt_sendBy
svc_commitmentRctRqt_sendTo_address
svc_commitmentRctRqt_sendTo_address_type
svc_commitmentRctRqt_sendBy
prc_type
prc_instance
deliveryRct_receivedAt
deliveryRct_identity
commitmentRct_identity
commitmentRct_decidedAt
commitmentRct_decision
commitmentRct_commitmentCode
If you don’t specify those properties you will get the following errors:
There was a failure executing the send pipeline: Reason: Invalid BTF message. The message is missing context properties eps_from_address that are required to generate a proper BTF envelope.
There was a failure executing the send pipeline: Reason: Invalid BTF message. The message is missing context properties eps_from_address_type that are required to generate a proper BTF envelope.
There was a failure executing the send pipeline: Reason: Invalid BTF message. The message is missing context properties eps_to_address that are required to generate a proper BTF envelope.
There was a failure executing the send pipeline: Reason: Invalid BTF message. The message is missing context properties eps_to_address_type that are required to generate a proper BTF envelope.
There was a failure executing the send pipeline: Reason: Invalid BTF message. The message is missing context properties prop_topic that are required to generate a proper BTF envelope
Here is an example of how you set those variables is the following properties:
InputMsg(BTF2.eps_from_address)=InputMsg(BTS.ReceivePortName);
InputMsg(BTF2.eps_from_address_type)=”Lab”
InputMsg(BTF2.eps_to_address)=”Order Directory”
InputMsg(BTF2.eps_to_address_type)=”XML”
InputMsg(BTF2.prop_topic)=”Order”
Which will make the following envelope around the message:
One of the most annoying things in BizTalk is when an error is generated in a Receive Pipeline indicating that a message has been suspended because of the content of the message doesn’t validate against the given schema (for the moment, we’ll gloss over the fact that in an ideal situation this should only ever happen during testing).
Using BizTalk 2006’s new Failed
Message Routing feature, it’s fairly simple to write something which can deal
with this situation (using either an Orchestration or SendPort subscribing to the
Error Report).
Returning a message back to a Web Service caller indicating that there is something
wrong with their message, is non-trivial – it’s possible, but requires some in-depth
knowledge of how instance subscriptions work.
However, there is an easier way: validating the message at the endpoint (i.e. inside
the Web Service itself).
Aaron Skonnard and
Dan Sullivan wrote an article for MSDN magazine in July 2003 on how
to implement attribute based schema validation for Web Method parameters.
It’s a great idea: decorate a Web Method with an attribute, and when the web method
is called then any messages received will be validated against their schemas – if
they don’t validate, then a SOAP Fault is returned back to the caller.
Looking through the code, I realised that with a few modifications it could work for
my situation.
The main issue with the code as it was is that, by default, it would validate incoming
XML messages against the XSD contained in the WSDL.
If you’re using the BizTalk Web Services Publishing Wizard, you’re probably
letting the tool do all the code generation for you. This also means that you’re probably
letting the .NET Framework look after generating your WSDL for you.
There’s a problem with auto-generation (as an aside, auto-generation might make your
life easier, but it can cause all sorts of problems if you’re not aware of how it
works, and what “default scenarios” it assumes).
Here’s what most people would do:
However, a C# class can’t fully represent an XML schema (and vice versa). Anyone who’s
worked with complex (real-world) schemas will have realized this.
One area where the whole thing falls over is when we put restrictions on attributes
or elements.
For example, suppose we an attribute called “name” which we wanted to restrict to
being between 1 and 20 chars long:
<xs:attribute
name=”name” use=”required“>
<xs:simpleType>
<xs:restriction
base=”xs:string“>
<xs:maxLength
value=”20” />
<xs:minLength
value=”1” />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
When this schema gets “converted” into a class representation, we get the following
for the attribute
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string name {
get {
return
this.nameField;
}
set {
this.nameField
= value;
}
}
And then when this class gets converted back to XSD again, we get this:
<xs:attribute
name=”name” type=”xs:string”
/>
All the restrictions have disappeared!
That’s because they’re not supported by the xsd.exe tool (or, more specifically,
by the internal classes used by xsd.exe to do the heavy lifting).
So that’s the problem with using the default SchemaValidator code: because
it validates incoming messages against the schemas in the WSDL, then unless you have
manually created your WSDL, the schemas in your WSDL will not be same as the original
schemas you created.
The solution is simple: validate the incoming messages against the original schemas.
And it just so happens that when you use the Web Services Publishing Wizard all
the original schemas are copied into the web service folder, in a sub folder called xsd.
What’s more, the original SchemaValidator code supports looking for schemas
in a folder called xsd – however, it simply has these take a backseat to the
ones in the WSDL.
Note: another solution is to handcraft your WSDL and put the original schemas
in there yourself – in fact, this is what everyone should do IMHO.
So the modifications I made to the original code are simple:
All the changes I made are in a single class: ValidationExtension.cs
How to use
Compile the solution, and then either copy the SchemaValidation.dll assembly into
your web service’s bin folder, or give the assembly a strong name and put it in the
GAC.
Then, update the web.config file for your web service as per the example given in
the solution:
<soapExtensionReflectorTypes>
<!– add type=”$SoapExtensionReflectorType.FullName$,
$AssemblyName.Name$” /–>
<add type=”SchemaValidation.ValidationExtensionReflector,
SchemaValidation, Version=1.0.0.0“/>
</soapExtensionReflectorTypes>
<serviceDescriptionFormatExtensionTypes>
<add type=”SchemaValidation.ValidationFormatExtension,
SchemaValidation, Version=1.0.0.0“/>
</serviceDescriptionFormatExtensionTypes>
Finally, open the code-behind file for your web service and do the following:
add a using SchemaValidation; statement
at the top
Add a [Validation] attribute
to all web methods where incoming messages should be validated
e.g.
[WebMethod]
[Validation]
public string Test(MyType bp)
{
Now if you call the web method with a message which doesn’t validate against the schema,
you’ll get a SOAP Fault similar to this:
<?xml version=”1.0″ encoding=”utf-16″?>
<soap:Envelope xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xmlns:xsd=”http://www.w3.org/2001/XMLSchema”>
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>System.Web.Services.Protocols.SoapException:
Incoming message failed validation: Error: The ‘name’ attribute is invalid – The value
” is invalid according to its datatype ‘String’ – The actual length is not equal
to the specified length.
at SchemaValidation.ValidationExtension.xrs_ValidationEventHandler(Object
sender, ValidationEventArgs e)
The code for this solution can be downloaded from here:
SchemaValidation.zip
(21.99 KB)
If you have any issues with it, let me know.
There are some good tutorials/walkthroughs on Bart De Smet’s blog and a good range of advanced WF topics such as Tracking, Persistence, and External Data Exchange. He breaks everything down into small chunks and makes it seem simple!
http://community.bartdesmet.net/blogs/bart/archive/category/1004.aspx
Benny Mathew
Seamless Integration Solutions
BizTalk Consulting, Development, Training
Bangalore, India
Website: http://www.seamless.in
Blog: http://GeeksWithBlogs.net/benny
BizTalk Usergroup: http://groups.google.co.in/group/b-bug
Last week I had to help a collegue with the Oracle adapter. To get started I used the following 2 articles:
Wilfried Mausz’s Oracle adapter demo
These two articles and some general BizTalk knowledge helped me to understand most of the Oracle adapter in very little time.
Sharing knowledge rocks! Thanks guys!