Monday, April 16, 2012

Mapping xs:any element to xs:base64Binary element


Source schema is containing <xs:any> element as shown below:


Destination schema is containing element with <xs:base64Binary> as data type as shown below:


To map the string value of <xs:any> element from source to Details element of type  <xs:base64Binary>  in destination. Drag a scripting functoid to map as shown below:


Use the following Inline C# code to convert string into Base64string:

public string GetBase64String(string stringData)
{
   byte[] encodedBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(stringData);
   return System.Convert.ToBase64String(encodedBytes);
}

Drag another scripting functoid and set script type to Inline XSLT as shown below:

 
Use following Inline XSLT code:

<Details xmlns:p="http://MappingBase64Encoded.SourceSchema">
  <xsl:value-of select="userCSharp:GetBase64String(string(/p:Record/Details/*))" />      
</Details>
Note: Here Details element refer to the element in the destination schema and this XPath is to extract the value of child element of Details as there is only one element if there are more then position of child element need to be specified.
Connect the second scripting functoid (having Inline XSLT) to Details element in destination schema as show below:
 
 

Testing the map

Source Instance used:
<ns0:Record xmlns:ns0="http://MappingBase64Encoded.SourceSchema">
  <Source>SourceElement</Source>
  <Details>
    <Data01>This is demo content from source.</Data01>
  </Details>
</ns0:Record>
Map output:
<ns0:Record xmlns:ns0="http://MappingBase64Encoded.DstSchema">
  <Source>SourceElement</Source>
  <Details>VGhpcyBpcyBkZW1vIGNvbnRlbnQgZnJvbSBzb3VyY2Uu</Details>
</ns0:Record>

Cheers
Rohit Sharma

Friday, March 23, 2012

Coping documents between libraries preserving the metadata


I faced a requirements in SharePoint 2007 where the documents need to be copied from one document library to another  document library in a different site (in different farm too) and the metadata of documents was also required to be preserved. I was able to do it using the Copy Web Service the GetItem Method generate a byte array representation of document and it also copied all the metadata in an array of FieldInformation object which can then be passes to CopyIntoItems method to upload the document in the destination document library.

I hope this would help other people finding the simple method of copying documents with metadata.

Cheers,
Rohit Sharma

Monday, February 20, 2012

How to initialize correlation set multiple times?

There was a question in Microsoft BizTalk Server General Forum where the requirement was to promote values on the messages extracted from a batch of messages using orchestration.

How it could be implemented?

To promote the properties in orchestration one need to initialize the correlation set as demonstrated by Sarvana Kumar in his blog. But you can initialize the correlation set only once so here is the way to initialize correlation set multiple times.

I am just extending the code shared by Stephen W. Thomas for Envelope and XPath Debatching in an Orchestration Lab

Download the code from above link and follow these steps:
Step 1. Run the Visual Studio Conversion Wizard to convert the solution.
Step 2. Remove PortDebatching project from solution you don’t need it for this excercise.

 Step 3. Open the XPathSample.odx and create a correlation type and correlation set as shown below:
 

Step 4. Create a variable with name CompanyName and type string and initialize it as shown below:
CompanyName=xpath(SingleInput,"string(/*[local-name()='Data' and namespace-uri()='']/*[local-name()='Company' and namespace-uri()=''])");

Step 5. Drop a message assignment shape in the ConstrustMapped shape and use the following expression:
SingleMapped(BTS.DestinationParty)=CompanyName;

Step 6. Select the send shape SendSingleMessage and initialize the correlation set Correlation_Party


If you will try to build this BizTalk Project now you will get the compile time error: “'Correlation_Party': a correlation may be initialized only once”


How to get rid of error “'Correlation_Party': a correlation may be initialized only once”?

- Add a scope shape to the loop and set the Transaction Type for this scope to Automic/Long Running/None.

Note: The only requirement is to have scope shape with the correlation set defined on this scope level. You can set the transaction type to None or atomic or long running  for the scope depending on your requirement.

- Cut the correlation set Correlation_Party  from orchestration level and paste it to the level of this new scope.

- Move the send shape to this new scope.


Note: Check once again that the send port is initializing the correlation set 'Correletaion_Party'.

Build and deploy the solution and you will see Destination Party get promoted with the value of company name for each message generated in the loop.


Cheers,
Rohit Sharma

Monday, January 2, 2012

BizTalk Server MVP 2012


First of all thanks to God, I can't expect any better start for this year. On this new year I got a great news of being Microsoft’s Most Valuable professional (MVP). I thank my peers, community members, fellow MVPs and Microsoft which honored me and recognized my contributions in BizTalk communities.

I'll continue to serve the BizTalk community more effectively with the best of my knowledge and experience.

Thanks
Rohit Sharma

Wednesday, November 23, 2011

error BEC2004: Unrecognized data in remaining stream.


Charan: Hey Rohit I am getting a weird error while validating the instance of a simple flat file schema in visual studio.
Following the the simple flat file message here InfoHeader is tag identifier


and here is the schema created for this flat file


while validating the flat file using this schema I am getting the "error BEC2004: Unrecognized data in remaining stream." in Visual Studio output window as shown below:


Rohit: I got your problem you are getting this error because you have specified Header as Tag Identifier (tag_name in above screen shot) while it should be InfoHeader as per your flat file message so change it as shown below.


Charan: Ah it resolved the issue!!!

Cheers
Rohit Sharma

Friday, September 2, 2011

Microsoft releases the Cumulative Update Package 2 for BizTalk Server 2010 and BizTalk Adapter Pack 2010

You can download  these updates from these links:

"This cumulative update package for Microsoft BizTalk Server 2010 contains hotfixes for the BizTalk Server 2010 issues that were resolved after the release of BizTalk Server 2010"

 

Prerequisites

To apply this cumulative update package, you must have BizTalk Server 2010 installed.
Note The following components are updated if they are installed:
  • Microsoft UDDI Services 3.0 that is included on the BizTalk Server 2010 installation disk
  • Microsoft BizTalk Adapters for Enterprise Applications (also known as BizTalk LOB Adapters)
"This cumulative update for BizTalk Adapter Pack 2010 contains hotfixes for BizTalk Adapter Pack 2010 issues that were fixed after the release of BizTalk Adapter Pack 2010."

Prerequisites

To apply this cumulative update package, you must have BizTalk Adapter Pack 2010 or Microsoft Windows Communication Foundation (WCF) Line-of-Business (LOB) Adapter SDK 2010 installed.