Processing binary documents through BizTalk via Web Services

Source: Internet
Author: User
Tags biztalk
Published 21 July 06 08:24 am | rseroter

Just finishing up a two-week BizTalk proof concept where I demonstrated an easier way to manage B2B interactions between a large insurance company and their vendors. this post is focused on one part of the solution that accepts binary messages via Web Services, and uses BizTalk to extract the message and send to SharePoint.

Instead of using dime or MTOM, this company exposes a web service where the vendor puts a binary blob into a Web Service Message Element. So how did I match this requirement? First, I started with the XML schema for the service interface. Instead of holding a binary node, myDocumentcontentNode holds a string (base64 ).

the most important step came next. How do you actually turn this string value back into a binary format to be consumed by BizTalk? I created a class (referencing Microsoft. xlangs. basetypes ) containing an implementation of the istreamfactory interface. the class constructor takes in the base64 string and saves it into a member variable. then, I implement the required createstream method which takes my value and returns a stream of bytes. createstream is used when inflating the message part to be sent to BizTalk. the entire class looks like this:

/// <Summary>
/// Class which implements XLANG istreamfactory and lets us define any content
/// To turn into a message. In this case, a string is converted back to binary format
/// And returned in the stream.
/// </Summary>
Public class mystreamfactory: istreamfactory
{
Private string messagecontent;

Public mystreamfactory (string inmessagecontent)
{
Messagecontent = inmessagecontent;
}
# Region istreamfactory members
Public System. Io. Stream createstream ()
{
Byte [] messagebytes = convert. frombase64string (messagecontent );

Return new system. Io. memorystream (messagebytes );
}

# Endregion
}

The next step was to create an object called from my orchestration that wocould take this string in, and return the requiredXlangmessageBack. I created a simple method which takes the inbound string and createsXlangmessageUsing the streamfactory created above. That class looks like this:

/// <Summary>
/// Method to call to generate XLANG message
/// </Summary>
Public class mymessagecreator
{
Public void createmymessage (xlangmessage outmessage, string binarystringmessage)
{
Outmessage [0]. loadfrom (New mystreamfactory (binarystringmessage ));
}
}
Note that I'm setting the first message partOutmessageAnd using the loadfrom method.

Back in my orchestration, I have an atomic scope within which I include a variable of TypeMymessagecreator. I created a message of type system. XML. xmldocument to hold the binary attachment. remember that a message of this type can hold * Anything * as long as you don't try and validate it or do XPath on it. so this will be the message I pass intoCreatemymessageMethod as the output parameter. The message assignment shape's code looks like this:

// Dummy Content Setup
Vendormessagedocument_attach = vendormessagedocument_response;

Messagecreator = new customer. POC. frauddetection. helper. mymessagecreator ();
Messagecreator. createmymessage (vendormessagedocument_attach, vendormessagedocument_response.documentcontent );

As you see from the top line, I had to set my "binary document" message equal to something else, just to instantiate it. That value will get overwritten by the subsequent callCreatemymessage.

So, after this part of the orchestration, I now have a valid BizTalk message with which to send to a port, which in my case, is a Sharepoint library. what I haven't shown yet is how to send this document to BizTalk the first place. I exposed this Orchestration as a web service, first of all. after referencing this service from my asp. NET page, I created an instance of the service class, the input document class, and went about taking the selected binary file (Word doc, PDF, Excel, whatever) and adding it to that document message. my code is as follows:

Binaryreader r = new binaryreader (docupload. filecontent );
Byte [] docbytes = R. readbytes (convert. toint32 (R. basestream. Length ));
String convertedtext = convert. tobase64string (docbytes );
R. Close ();
// Add this now-formatted base64 string to the Web Service Message Payload
Doc. documentcontent = convertedtext;

I submit that message, and we're on our way! So as I 've shown, you can accept random binary content within a message payload itself (SANS attachment), create a valid BizTalk message which contains that binary content, and send it out. sweet. now I cocould easily enhance this by accepting binary content. strings, or doing the processing in a pipeline. the orchestration. maybe later

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.