Showing posts with label biztalk config. Show all posts
Showing posts with label biztalk config. Show all posts

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