Thursday, August 20, 2009

Handling multipart MIME messages in Biztalk

Scenario:
I am trying to handle multi part MIME messages in Biztalk 2004.My Scenario is like this
I have a flat file which has two parts.The first part is of content type:text/plain and the second part is of Content type:application/pdf with encoding :base64.
What i need to do is,i receive this text file and send a xml output with
the pdf as the attachment.the problem is,i am able to generate the xml file but not the pdf attachment.Is anyone familiar with this issue.please let me know.i am pasting a part of the text file for your reference
--------------------File start------------------- MIME-Version: 1.0 Content-Type: multipart/related; type="text/plain"; start="application/ms-cimessage"; boundary="----=_NextPart_001"
This is a multi-part message in MIME format.
------=_NextPart_001 Content-Type: text/plain; Charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-ID:
DOCFLATRESP087096350 ZZ087096350ZZ937748440937748440087096350A4026 A4026 0
90029627138363-26 WASHINGTON JOHN A123456789WASHINGTON MARIA B222112222123 QA ROAD TESTERVILLE PA1910390000.00 100000.00 Commitment0410200639.00 39 25.0 BYMNSP0.5200.5200.0000.0000.0001
001359 ------=_NextPart_001 Content-Type: application/pdf Content-Transfer-Encoding: base64 Content-ID: Content-Disposition: attachment; filename=Cert_90029627-Date_20051012-114553-CorrID_A4026.pdf
JVBERi0xLjMKJa0KMSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwovUGFnZXMgMzEgMCBSCi9PdXR­­saW5lcyAzMiAwIFIKL1ZpZXdlclByZWZlcmVuY2VzIDIgMCBSCi9PcGVuQWN0aW9uIFswIC9YW­V­ogMCA3OTIgMF0KPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1ZpZXdlclByZWZlcmVuY2V­zC­i9IaWRlVG9vbGJhciBmYWxzZSAvSGlkZU1lbnViYXIgZmFsc2UgPj4KZW5kb2JqCjMgMCBvY­moK­Wy9QREYgL1RleHQgL0ltYWdlQ10KZW5kb2JqCjQgMCBvYmoKPDwKL1R5cGUgL0ZvbnQKL1N­1YnR­5cGUgL1R5cGUxCi9OYW1lIC9GMQovQmFzZUZvbnQgL0NvdXJpZXIKL0Vu
------=_NextPart_001

Solution:

Here are the Steps assuming that you want to convert a MUltipart flat file MIME file into and XML with pdf attachment.This scenario is valid for any output file with any number of attachments.
Assumptions:
1.You must have the Receive Flat File Schema.Mine was a positional Schema. 2.If you have a map,make sure your map works.
Solution.
1.Create a Receive pipeline.Add a MIME/SMIME decoder in the decode Section.you don't have to modify any properties.This decoder automatically decodes your Mime Input messages. 2.Add Flat File or XML Dissembles if needed. 3.In the Orchestration ,Create a Multipart Message Type.If you have 1 attachment,Create 2 MultiParts and Set the Types as "System.XML.XMLDocument". 4.Create 2 Message Types to separate the input text file into the required number of files. a)Set the Body Message of Message Type=Flate File Schema b)Set the Attachment Message of Message Type=System.String 5.Place a receive .Place a construct Message.Add 2 message assignments inside the Construct Message.Here is where you separate the input message into the required 2 documents. 6.In the First message Assigment ,set the msgBody to the MultipartBody Type like this msgBody=msgMultiPart.MultiPartXml;(Based on my Example).Where msgBody is the message and msgMultiPart is my Multipart message 7.Similarly in the Second Message Assigment,set the msgAssignment to multipartPDF Type like this msgAttachment=msgMultiPart.msgPDFPart; 8.From here its a straight forward mapping or sending the output.For my
solution ,i have a parallel shape which posts the msgBody after mapping
to a response location, and the msgAssignment is also posted out to the
same response/send location.

Soap Envelope Senario and Soap envelope on Part of MIME Document Response Options


Scenario:
We are doing a migration from Biztalk 2000 to Biztalk 2004.Previosly out Trading partner used to send an XML with Soap Envelope to an ASP file.The ASP used the Biztalk Interchange to Post to Biztalk2000.After Processing Biztalk sends back the response to the Trading Partner with the Soap Envelope.
I am trying to find out how its adding the Soap Envelope when its sending the response.
In the Migrated Scenario i am able to establish everything in the Response file except the SOAP Envelope.
i am not using the Biztalk interchange in the new Migrated Biztalk 2004.I am receiving the file in the ASP and dropping the file in the folder for Biztalk 2004 to pick it up from there.Biztalk 2004 picks up the file from the folder,process the file and then sends it to the Trading Partner.

Solution

---------------------------------------------------------------------------­---------------------------------------------
Use the BTF assembler in a send pipeline. You can add the same information that was used in earlier versions. I used the assembler when migrating a BT2002 project that used SOAP in the same manner you described.
---------------------------------------------------------------------------­----------------------------------------------

Scenario

I have to send a MIME Document response to the trading Partner.I have figured out everything except on how to add a soap envelope only to a part of the Multipart Mime response.When i was using the Biztalk FrameWork Assembler in my send pipeline to set the soap details it gives me this error
" '<', hexadecimal value 0x3C, is an invalid attribute character" Can anyone help me in pointing out what i am doing wrong.Can anyone tell me if i can use the Biztalk Framework Assembler in .net code and call it in orchestration.If i can do that how do i set the values and properties in .net.



Solution:
In my Example ,i receive a multipart mime and send out a multipart mime.The Multipart type i used was of Systm.XML.XMLDocument.
if i use the XML Document as the Multpart type for the Attachment part the encoding errors out because it is expecting a XML.
In order to resolve this problem ,Microsoft has a solution of creating a RawString Type.The RawString Type should be used for the multipart if the second part is PDF.
The code for creating a Raw String is below
using System; using System.IO; using System.Text; using System.Xml.Serialization; using System.Runtime.Serialization;
using Microsoft.XLANGs.BaseTypes;
namespace Microsoft.Samples.BizTalk.XlangCustomFormatters { public abstract class BaseFormatter : IFormatter { public virtual SerializationBinder Binder { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } }
public virtual StreamingContext Context { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } }
public virtual ISurrogateSelector SurrogateSelector { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } }
public abstract void Serialize( Stream stm, object obj ); public abstract object Deserialize( Stream stm ); }
public class RawStringFormatter : BaseFormatter { public override void Serialize(Stream s, object o) { RawString rs = (RawString)o; byte[] ba = rs.ToByteArray(); s.Write( ba, 0, ba.Length ); }
public override object Deserialize(Stream stm) { StreamReader sr = new StreamReader( stm, true ); string s = sr.ReadToEnd(); return new RawString( s ); } }
[CustomFormatter(typeof(RawStringFormatter))] [Serializable] public class RawString { [XmlIgnore] string _val;
public RawString(string s ) { if (null==s) throw new ArgumentNullException(); _val = s; }
public RawString() { }
public byte[] ToByteArray() { return Encoding.UTF8.GetBytes( _val ); }
public override string ToString() { return _val; } }
} Also at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sdk/htm/ebiz_prog_email_ibad.asp
Write this code in .Net and import the assembly in your Biztalk Solution.
You will now be able to set the Multipart PDF type to a raw string.
This solved my problem.

MIME Encoding in .Net

I was wondering if we can implement the MIME encoder and the MIME Decoder methods and properties in a class library and call it in Biztalk Orchestration.I am using Biztalk 2004.My scenario is that"
I have one encoded MIME File with 2 parts.
First Part is XML and the other is a PDF.
The XML Part which comes to me Encoded,i want to decode and send to my client.Now the PDF part which is also encoded text , i don't want to touch.So i want to used MIME encoder only to a partial part of my File(that is the XML part).Is this possible.Can anyone give me a alternate solution?



I was able to find a solution to my problem without using the adapter.
What i did was :
1.In a .net class library i was able to set the ContentTransferEncoding
Type 2.In the orchestration i used the class library to specify the contentTransferEncoding to my attachment part. 3.The attachment has to be an System.XML.XmlDocument.Otherwise this solution wont work. 4.I set the mime encoder in the send pipeline for the body part as "7 bit" and in the orchestration i set the attachment part of Type Base64.
5.This way i was able to generate a MIME file of 2 Content types I have here the .net code that i used for your reference and the code i
used in the orchestration.
.net Code ------------------------------------------- public class Part { public Part() { } public static void SetContentType(Microsoft.XLANGs.BaseTypes.XLANGPart part, string contentTypeValue) { part.SetPartProperty( typeof(Microsoft.XLANGs.BaseTypes.ContentType), contentTypeValue); } public static void SetContentTransferEncoding(Microsoft.XLANGs.BaseTypes.XLANGPart part,string ContentEncoding) { part.SetPartProperty( typeof(MIME.ContentTransferEncoding), ContentEncoding); } public static void SetFileName(Microsoft.XLANGs.BaseTypes.XLANGPart part, string fileName) { part.SetPartProperty( typeof(MIME.FileName), fileName); }
}
---------------------------------------------------------------
Orchestration Code ------------------------------
msgMultiResp.MultiPartMsgPDF=msgAttachment; MIMECustomise.Part.SetContentTransferEncoding(msgMultiResp.MultiPartMsgPDF,­­"Base64");
msgMultiResp(MIME.IsMultipartRelated)=true;
Note:This is a multipart message

Configuring Biztalk across Remote SQL Server

I would like to Share information about configuring Biztalk while configuring the databases on a remote SQL Server Machine.This information should be valid for people who are trying to configure Biztalk on a Remote Sql Server Machine either in the same domain or a different domain.My implementation involves Biztalk and Sql Server on Win 2000 Server.Problems like
"Failed to deploy BizTalk system assembly "C:\Program Files\Microsoft BizTalk Server 2004 Microsoft.BizTalk.GlobalPropertySchemas.dll". Unspecified exception: An error occurred while enlisting in a distributed transaction."
"Failed to deploy BizTalk system assembly "C:\Program Files\Microsoft BizTalk Server 2004
Microsoft.BizTalk.GlobalPropertySchemas.dll". Unspecified exception:Eventlog is full"
Assumptions:
1.Sql Server is installed on the remote Maching with all the Biztalk requisites. 2.MSDTC is installed on both the Biztalk and SQL Box.Include MSDTC in the firewall exceptions if any. 3.Try pinging the machines ,from each other.If necessary trouble shoot using the DTCping tool.Look for DTCPing.exe in the below link.
http://support.microsoft.com/default.aspx?scid=kb;en-us;306843 4.If you get the error which says "your eventlog is full",Make sure you clear you the Eventlog on both the Servers hosting biztalk and SQL Server.Clear Event log by using Eventviewer. Run-->eventvwr.msc
Make a copy of the previous eventviewr information if necessary.
5.Open ports for network TCP/IP 5000-5200. Administrative Tools-->Component Services-->My Computer-->Right Click -->Properties-->Default Protocols Tab-->Conn Oriented Tcp/IP-->ADD 5000-5200 port range.
6.These were the above steps i took to get Biztalk Configuration installed across MultiServer.
Let me know how this works and mail me if you have any questions.Feel free to correct my diagnosis.

Migrating Biztalk 2000 and 2002 versions

4 years back I worked on a Biztalk migration from 00 to 04 . I am also currently in the processing for upgrading biztalk 02 to Biztalk R2 version.I had to migrate the following which were the tougher ones
AIC, Maps
We had maps with Vbscript as that language seemed to be the most commonly used one back in 2000 and 2002.Like you said the migration wizard dosent help at all.Here is what I did.Hope it helps
1.For each of the specification document[DTD] ,you will need to convert them to an XSD or recreate if necessary for all the DTD's thats are hard to convert. 2.Visual Studio has an option to convert the DTD to an XSD either by opening the DTD,Menu-->>XML-->Create Schema or the other option is use the Schema generation wizard to create a XSD out of a DTD. 3.Get the xsl from the Biztalk 02 map.You can do this by compiling the map and the xsl is outputed. 4.Once you have successfully converted your source and destination schemas,create a new map and assign the new schemas as source and destination. 5.The xsl that you got in step 3 should be set in the custom xslt property. 6.When you test the map,you will notice that vb script is no longer supported.You will have to manually convert vb script to VB.net code.The best way i found for this was to take the vb script code and converted to code using a wizard and then manually corrected the output for it to work. 7.Once you have the new xsl,yours map should work without any issue. 8.The disadvantage of this process is that you cant see any functoids from the previous maps,but you will be able to add new functoids on the new map.
The remaining solution should be straight forward.If you have an AIC,you can convert the AIC to a custom adapter or re-write the AIC as a .net component or webservice.
I understand this could be a pain doing this for 3000 to 4000 maps.But I don't see any another solution from my point.If anyone else has a better approach,please advice.

Wednesday, April 29, 2009

Msmq Export and Import Tool

This MSMQ export tool that will automatically export all the MSMQ's from the current server by creating a config file.Using this Export tool you can then import the queues on any server of your choice by simply taking the config file with you.The config file also lets you set the security permissions for the queue. If you need the tool, email me at vamsibm@gmail.com or download it from
http://www.sendspace.com/file/hemjug

To extract the contents,please rename the txt file to zip and when you extract the zip folder,rename the .dat to .exe format..The read me is a part of the extract folder Tools.zip