Thursday, October 22, 2009

Using the Lob WCF-Custom SQL Adapter to Submit a message to SSB queue from BizTalk


Hi All,
Recently on a project I had an integration where the destination wanted BizTalk to drop the message in a SQL Service Broker Queue.
The first thing I thought when I heard it was "SQL Queue?".Heard of MSMQ but SQL Queue,when did Microsoft come up with this concept.I really never heard of it and why we use it.
So I started googling on SQL Service Broker and found this good MSDN section
http://msdn.microsoft.com/en-us/library/bb522893.aspx
Here you will also find some tutorials to start working on
http://msdn.microsoft.com/en-us/library/bb839489.aspx

So after gaining some SQL Borker knowledge I googled as how this  works with BizTalk.
For a scenario where
BizTalk needs to read a message from the SSB Queue this article from WCF Lob Adapter pack Team was a perfect sample.
http://blogs.msdn.com/adapters/archive/2008/06/30/using-the-wcf-sql-adapter-to-read-messages-from-ssb-queues-and-submit-them-to-biztalk.aspx
So now I know how BizTalk how BizTalk can read a Message from a SSB Queue.
But what about Sending a message to the SSB Queue?
So lets start with a simple scenario for this.

1.I will have to Enable SQL Service Broker on any database.Lets use the Master database for our scenario.
2.Note we dont need to create any table to work with SSB Queues and BizTalk.So you can Create a new Database and enable SSB on it.
2.Then we need to create a new Queue.
3.Run this Script in the SQL Query window and you should be ready with the basic setup.

USE master;
GO
ALTER DATABASE master SET NEW_BROKER with rollback immediate;
ALTER DATABASE master SET ENABLE_BROKER with rollback immediate;

GO
USE <your db name here>;
GO

CREATE MESSAGE TYPE
    [Message1]
    VALIDATION = None;

CREATE CONTRACT [Contract1]
    ([Message1]
    SENT BY ANY
    );

CREATE QUEUE Queue1;

CREATE SERVICE
    Service1
    ON QUEUE Queue1(Contract1);



So I created only 1 Queue named "Queue1" and with a contract and message type.
Dont worry this is not Biztalk MessageType.
Now we will create a SQL Stored Procedure which will insert a xml in this queue.
USE [master]
GO
/****** Object:  StoredProcedure [dbo].[InsertMsgInQueue]    Script Date: 10/01/2009 11:47:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:  <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
Create PROCEDURE [dbo].[InsertMsgInQueue]
 -- Add the parameters for the stored procedure here
 @XMLIn XML
AS
BEGIN
 DECLARE @RequestMsg XML;
SELECT @RequestMsg = @XMLIn;
  DECLARE @DlgHandle UNIQUEIDENTIFIER; BEGIN DIALOG @DlgHandle
  FROM SERVICE [Service1] TO SERVICE N'Service1'
  ON CONTRACT [Contract1] WITH ENCRYPTION = OFF
  SEND ON CONVERSATION @DlgHandle MESSAGE TYPE [Message1] (@RequestMsg);
END


Now I will have to call this generic SP from BizTalk Send port and insert any XML in the SSB Queue(Queue1).
So now its time for BizTalk part of this Scenario.
Scenario :When we drop a file in a Folder  the Receive port picks up the file and sends the file to the Send Port via a Filter(ReceivePortName).
I hope every BizTalk Developer knows how this works....ping me if you dont.
No Orchestration is involved.
Next we need to configure the Send port so we can send the message to the Queue.
Just configure the Send port as Shown below in Screen1 and Screen2.

Screen1

Screen2
The Template code inside Screen2 is
<InsertMsgInQueue xmlns="http://schemas.microsoft.com/Sql/2008/05/Procedures/dbo">
<XMLIn>
<bts-msg-body xmlns="
http://www.microsoft.com/schemas/bts2007" encoding="string"/>
</XMLIn>
</InsertMsgInQueue>

Thats it.
Now start the ports drop any xml file in the "In" Folder and it should be insert inside the Queue.
No Orchestration,Only pure Message Based Routing simple solution.
Hope it helps somebody as I found it tough when I googled for a sample on this scenario.
So this was it all about Sql Service Broker and BizTalk.
Happy BizTalking.

Monday, June 15, 2009

Biztalk BAM Portal Issues


Hi,
I tried to configure BAM for the first time and failed with error Access Denied 401.2.
Event code: 4007
Event message: URL authorization failed for the request.
Event time: 15.06.2009 10:21:22
Event time (UTC): 15.06.2009 08:21:22
Event ID: db49acbf6d1c42d9b3228e5e8abdf0ce
Event sequence: 2
Event occurrence: 1
Event detail code: 0

Application information:
    Application domain: /LM/W3SVC/1/ROOT/BAM-1-128895276813021664
    Trust level: BAMPortal_Minimal
    Application Virtual Path: /BAM
    Application Path: C:\Program Files\Microsoft BizTalk Server 2009\BAMPortal\

Process information:
    Process ID: 5172
    Process name: w3wp.exe
    Account name: NISHIL\Administrator

Request information:
    Request URL: 
http://localhost/BAM/Default.aspx
    Request path: /BAM/Default.aspx
    User host address: ::1
    User: NISHIL\Administrator
    Is authenticated: True

I configured BAM using Administrator account as User everywhere ,even on the BAM App pool ,So for sure I knew this error is not about authentication.
What I found is in Biztalk Configuration Tool under BAM portal I had selected windows group "Role Name" ,"Bam Portal Users" as "Administrators" so that the Administrator User can easily access the portal.
But this is not correct.
I reconfigured BAM portal using "Role Name" as "Biztalk Server Administrators" and it worked fine.
Might be the group needs to be one of the Biztalk groups.Hope this post helps somebody.
------------------------------------------------------------------------
Other Solutions found on google which did not work for me were
1).Adding IIS 6 Management tools for backaward compatilibity since I use Windows 2008 and IIS 7 and Biztalk 2009.
2).Changing AuthenticationProviders cscript adsutil.vbs set w3svc/NTAuthenticationProviders "NTLM"