Wednesday, December 31, 2008

WELCOME HAPPY NEW YEAR 2009

 

Hello Friends.

Wish you all very Happy New Year 2009. 

Never Ending Welcomes YEt to ARrive.

image

 

image

 

Thanks

SreenivasaRagavan.

WCF & BizTalk -Exposing WCF Service out of BizTalk Server.

 

In this Blog I am going show how to expose BizTalk Server 2009 Schema as a WCF Service using BizTalk Server WCF publishing Wizard.

First we need to create Empty BizTalk 2009 Project and Add Schema to that project.

Here I created the Contacts XSD with the following Child Elements.

<Name>Name_0</Name>

<Email>Email_0</Email>

<Phone>Phone_0</Phone>

 

image

Now Build this project and deploy into BizTalk server DB.

Launch the BizTalk Server WCF Service Publishing Wizard 

image

image

 

Enable metadata endpoint Checking check box  causes the “httpGetEnabled” flag to be set to true, thus enabling  Client application  to retrieve the WSDL for this service.

image

Now select the BizTalk application name which you want to expose as WCF Service.  here we need to select the project we deploy into BTS Server.

image

 

Now we asked whether we want “Publish orchestrations as WCF service” or “Publish schemas as WCF service.”  This both options same as classic BizTalk Web Services Publishing Wizard.  Now we will choose Publish schemas  option.

image

Here we are going to Add method to our WCF Service .

image

Select the Schema type for the method we just created.

image

Provide the Namespace for the WCF Service.

image

 

Provide the IIS Server Location to create the WCF Service. check allow Anonymous Access.

 

image

 

image

 

Go to IIS Manger and  you can see the WCF Service web application is created with  .SVC file

 

 

image

Browse the WCF  .SVC file.   Now you  created WCF service.

image

 

Configure the BizTalk server Receive and Send ports.

Now let's create the Windows Client and consume the  BizTalkServiceInstance WCF Service.

 

image

Run the client Application , now you will see  Message  in BTS Send ports.

image

 

Thanks

SreenivasaRagavan.

Tuesday, December 30, 2008

Calling WCF Service from BTS-2009

 

First let's create a simple WCF service that Biztalk server will call.

Here is my ServiceContract and Implementation of the  Service Contract.

image

I am Hosting this WCF service in  Console Application (Self hosting).

image 

Now  I need to actually start up my WCF service host. Now BizTalk can interrogate this service to extract the necessary metadata. Within Visual Studio.NET, I chose “Consume WCF Service” from the “Add Generated Items” project menu.

Now create Empty Biztalk Project. Right click on the project and select Add Generated Items as shown below.

image

From Add Generated Items Dialog select Consuming WCF Service Template.

image

 

Now Follow the  BizTalk WCF Service Consuming Wizard.

image

Here Edit the WCF Service MEX endpoint URL

image

Before doing above step make sure that WCF service UP and Running ( Remember We hosted this service in console App).

image

 

image

 

image

 

Now we are successfully finished the Wizard.

image

WCF Service Consuming Wizard Generates the following files.

image

 

Now Open the SreeniImpl.odx Orchestration Create a message for the WCF Service Add Operation and configure the  Receive and Send Ports.

image

Now Build and Deploy the Application and Open up the Biztalk 2009 Admin Console.

Our WCF service build with Basic HTTP binding so  in Biztalk we need to configure send port Transport type as WCF-Basic HTTP as shown below.

image

Now configure the send port as shown below.

image

 

Now configure the Receive port as shown below .

image

Now test the  Biztalk application.

Input XML Message

<ns0:Add xmlns:ns0="http://tempuri.org/">

<ns0:a>5000</ns0:a>

<ns0:b>18</ns0:b>

</ns0:Add>

when we drop the input XML message in Receive Location Biztalk server call WCF service Add Operation.

image

Output XML Message:

<?xml version="1.0" encoding="utf-8" ?>

<AddResponse xmlns="http://tempuri.org/">

<AddResult>5018</AddResult>

</AddResponse>

 

Thanks

SreenivasaRagavan,

Sunday, December 28, 2008

Extension Methods in C# 3.0

 

An extension method is a new language feature of C#. This methods provides a ability to "ADD" methods to an existing types without creating a new derived type.

Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type.

In my current project I had Business Object called LOT  this is C# class with the following properties .

public class Lot
   {
       public string lotNumber {get;set;}
       public string lotDescription { get; set; }
       public string customerName { get; set; }
       public string metalId { get; set; };
   }

when I pass this Lot Information to Back end ERP System I need to format with padding Zero ( total length of the lotNumber field is 14 in DB).

Here comes new C# 3.0  Extension Methods for handy .

Extension methods are defined as static methods but are called by using instance method syntax. Their first parameter specifies which type the method operates on, and the parameter is preceded by the this modifier. Extension methods are only in scope when you explicitly import the namespace into your source code with a using directive.

Here is my Extension methods.

image

image

image

for more Information about  C# Extension Methods POINT your IE to EXTENSION METHODS

Thanks

SreenivasaRagavan.

Saturday, December 27, 2008

Promoting Property Vs Distinguished fields

 

The property fields are promoted so that their values can be referenced for content based routing purposes inside  orchestration, Pipeline, Receive and Send ports. A term  Promoting a Property is commonly used to describe a message’s promoted properties is message context.

 

     Property Promotion

 Distinguish field

 

Promoted field available in all the following BizTalk artifacts such as Receive, send ports, Pipelines, Orchestration.

 

Promoted properties are max Length of 255 Char

 

 

Promoted properties are persisted to the Message box database.

 

Distinguish filed only available in single instance of Orchestration.

 

 

Distinguish filed can be any length.

 

Distinguished fields have less of a performance impact than promoted properties, as

They are not persisted to the MessageBox database. Instead, they are essentially XPath

aliases, which simply point to the appropriate XML data field.

 

Here I am promoting the  Age Property of the Contact.XSD

image

Once I Promote the age Property I can Filter the message (CBR) based on Age in my  Receive , Send and Orchestration.

 

image

After promoting the Age Property you see difference in Age Element. ( Small Yellow circle on top). 

image

Once you have deployed the solution with the promoted properties, they may be used to
perform content-based routing (CBR).

for example:  Suppose  I am receiving two Message with different age I can Route this message to two different send port  based on age. 

First send port  : Only Age  > =10

Second Send port Only < 10

Message 1:

<ns0:Contact xmlns:ns0="http://BizTalk_Server_Project1.Contacts">

<Name>Name_0</Name>

<Age>10</Age>

<Email>Email_0</Email>

<Phone>Phone_0</Phone>

</ns0:Contact>

 

Message 2:

 

<ns0:Contact xmlns:ns0="http://BizTalk_Server_Project1.Contacts">

<Name>Name_0</Name>

<Age>25</Age>

<Email>Email_0</Email>

<Phone>Phone_0</Phone>

</ns0:Contact>

 

Thanks

SreenivasaRagavan.

How to create custom Functoid [for Biztalk Mapper]

 

What is Functoid?

The term Functoids refers to predefined functions within the Biztalk Mapper tool set. Functoid's support
a number of useful translations and transformations.

Here are the steps to create, deploy and test the Custom Functoid.

1) Create a C# Class Library Project

2) Add Reference Microsoft.BizTalk.BaseFunctoids.dll to the project you can find this  DLL from the following  Folder [ Biztalk sever should be installed to get this Assembly]

image

3)  Add Resource file VS.NET Template to the project for to store Functoid Configuration parameters. and add the following Resource string and values.

image

4) Add Custom Functoid class and that should derive from BaseFunctoid class as shown below.

 

image

Here is the my custom function implementation.

image

 

When Overriding the Constructor we need to perform the following primary tasks as shown in the table.

[  Source : Microsoft  here is the link Custom Functoid]

Task

Use these methods or properties

Comments

Assign a unique ID to the functoid

ID

Use a value greater than 6000 that has not been used. Values less than 6000 are reserved for use by internal functoids.

Indicate whether the functoid has side effects

HasSideEffects

Used by the mapper to optimize the XSLT code that is generated. This property is true by default.

Point to the resource assembly

SetupResourceAssembly

Include a resource file with your project. If building with Visual Studio, the resource assembly must be ProjectName.ResourceName.

Enable the custom functoid to appear in the BizTalk Mapper palette

SetName

SetTooltip

SetDescription

SetBitmap

Use a resource ID pointing to a string for the name, tooltip and description; use a 16x16-pixel bitmap.

Assign the functoid to one or more categories

Category

Categorize the functoid by using one or more FunctoidCategory values.

Specify the number of parameters accepted

SetMinParams

SetMaxParams

HasVariableInputs

Use the SetMinParams method to set the number of required parameters and the SetMaxParams method to set the number of optional parameters. Use the following guidelines to set these values:

·         If you have no optional parameters, set min = max.

·         If you have some optional parameters, set max = (number of optional parameters - min number of parameters).

·         If you want to allow unlimited optional parameters, do not set max.

·         If you have a variable number of inputs, do not set min or max, and set HasVariableInputs = true.

Declare what can connect to your functoid

AddInputConnectionType

Call AddInputConnectionType once for each ConnectionType that the functoid supports.

Declare what your functoid can connect to

OutputConnectionType

Use values from ConnectionType to tell BizTalk Mapper the types of objects that can receive output from your functoid. Use OR to specify multiple connection types.

Tell BizTalk Server which methods to invoke for your functoid

SetExternalFunctionName

SetExternalFunctionName2

SetExternalFunctionName3

For cumulative functoids, use SetExternalFunctionName to set the initialization function, SetExternalFunctionName2 to set the accumulation function, and SetExternalFunctionName3 to specify the function that returns the accumulated value. For noncumulative functoids use SetExternalFunctionName to set the functoid method.

Have BizTalk Server use inline code to invoke your functoid

AddScriptTypeSupport SetScriptBuffer

Call AddScriptTypeSupport with ScriptType to enable inline code. Invoke SetScriptBuffer to pass in the code for the functoid. This code will be copied into the map.

Declare global variables for an inline functoid

SetScriptGlobalBuffer

Any declarations made will be visible to other inline scripts included in the map.

Indicate which helper functions your inline functoid requires

RequiredGlobalHelperFunctions

Use values from the InlineGlobalHelperFunction enumeration to specify which helper functions are required. Use OR to specify multiple helper functions.

Validate parameters passed to your functoid

IsDate

IsNumeric

These functions provide a true/false answer without throwing an exception.

5) Add Strong Name Key to the project this can be done from  VS.NET IDE itself or we can use  SN.EXE  from VS.NET command prompt .

6) Now copy the Build DLL into the following  Windows Folder. this is the place where BIZTALK server looks for custom Functoids.

image

 

7) Add Custom Functoid to  VS.NET Tool Box 

image

 

8. Add the functoid to the Global Assembly Cache (GAC) [ To add Assembly to GAC  the assembly has to build with Strong Name].

Now create a Biztalk MAP and test the Custom Functoid

image

Input XML Instance:

<ns0:Root xmlns:ns0="http://BizTalk_Server_Project1.Schema1">

<Id>AG</Id>

</ns0:Root>

 

Map Out put XML : ( with custom Functoid)

<ns0:Root xmlns:ns0="http://BizTalk_Server_Project1.Schema2">

<ID>SILVER</ID>

</ns0:Root>

Thanks

Sreenivasaragavan.

Friday, December 26, 2008

While I am in REST , I thought of doing REST with WCF.

 

Today I installed  WCF REST start kit from CodePlex .  here is the link to download WCF REST STARTER KIT

What is Inside WCF Starter Kit?

WCF REST Starter Kit is a set of features, Visual Studio templates, samples and guidance that enable users to create REST style services using WCF. Visual Studio templates for creating REST style services such as an Atom feed service, a REST-RPC hybrid service, Resource singleton and collection services and an Atom Publishing Protocol service.

image

VS.NET 2008  REST Templates.

image

 

Thanks

SreenivasaRagavan.

Wednesday, December 24, 2008

Debatching BizTalk XML Messages.

 

What is debatching?

Suppose you are receiving a BizTalk Message  that contains multiple records. In order to process the message and update or send to particular system (DB or any other Application) we need to process this message individually this process called debatching in BizTalk.

How BizTalk helps ?

In BizTalk  using Envelope Schema, Document schema we can process or break a message  individually .

Steps Needed to Achieve this.

1) First Create document schema which has all the elements of the XML  message. and call this schema as Contact.XSD

  Here I am going to use The following XML Message

<Name>Sreeni</Name>
<Age>35</Age>
<Email>sragavan@hotmail.com</Email>

<Name>Gandhi</Name>
  <Age>35</Age>
  <Email>Gandhi@india.com</Email>

2) Create Envelope schema and name it  Contacts

image

Now select Schema node in newly created schema and set Envelope Property to  "YES" as shown above.

Now we need to Import Contact Document schema into Envelope schema.

image

image

Now add child record and name it Contact and change the  Data structure type to  Contact as shown below.

 

image

Now  change the Body Xpath  to /*[local-name()='Contacts' and namespace-uri()='http://XmlDebatching.ContactsEnvelope']

Step 3:

Now create custom Receive Pipeline with XML Disassembler  as shown below.

and Change the document schema to Contact.XSD and  Envelope schema to ContactsEnvelop.XSD.

 

image

finally Add Strong Name key file to the project and Deploy into BizTalk Message DB.

Create  Receive Port with the custom pipeline we created and Send port with  Filters  and  test the application.

Now drop the  Contacts.XML in  Receive Location  and BizTalk Read the message and Split into individual messages as shown here.

image

image

 

image

Thanks

SreenivasaRagavan.