BizTalk Server 2010 + SQL Server 2008 R2 - 通过集成创造更大价值 [ 上篇 ]

概述

对于IT信息技术来说,应用程序和数据就好像太极的阴阳两极,通过对这两者进行组合,即可获得 IT的业务价值。虽然公司、ZF机关需要使用大量不同应用程序,并用不同格式存储数据,但为了从这种多样化中充分获益,往往需要用智能的方式将所有内容进行连接。换句话说,也就是需要集成!

在集成的过程中可能会产生很多非常麻烦的问题,通常存在于公司、ZF机关中的都是大量的异构系统、异构数据。每种应用程序拥有自己的立场和特有的表现形式,并且随着时间的流逝,IT环境慢慢变得更加复杂。根据不同业务的需求,会由不同部门在不同地点部署不同的应用程序和数据库。这些因素使得集成工作面临重大挑战,这种挑战有可能出自于技术上的,也有可能出自于业务上的。

为了面对这一挑战,我们通过BizTalk与SQL Server的结合,为业务创造出更大的价值。

  • BizTalk Server:其重点在于连接不同的应用系统,并基于SOA的架构对来自异构系统的服务进行流程编排和重组,从而对多个业务流程实现自动化;同时,也可以使用它进行某些类型的数据集成,并对数据进行权威清晰、过滤、比对等操作。
  • SQL Server:目标是使用更智能的方式来操作数据,这也就意味着需要在不同的应用系统间保持数据同步,或创建数据仓库等等。

在这篇文章中将介绍如何通过BizTalk将来自于各个异构应用系统的数据,传送到SQL Server数据库当中,并介绍如何使用BizTalk与数据库进行通信,如调用存储过程等等。


演示

场景介绍

在这里我们有一个SQL的存储过程,用来更新仓库库存量,现在我们要做一个BizTalk的POC(概念验证),当接收到仓库补充货源消息的时候,使用BizTalk去调用SQL Server中的存储过程,来更新仓库的库存量。在演示过程中,我们会用到WCF-SQL适配器去调用SQL存储过程,并且设计一个测试流程来转换补充货源的消息,并将其作为参数传送到存储过程中进行更新,最后将更新的结果通过WCF-SQL适配器插入到数据表当中。

1. InventoryUpdate解决方案:在这个解决方案中有2个工程文件,分别为InventoryUpdate.OrchestrationInventoryUpdate.Schema。Schema工程文件中包含一个名为StoreInventoryUpdate的架构文件,它用来表示一个来自于POS系统发送过来的更新玩具商店库存的消息。Orchestration工程文件目前没有内容,我们会在后面完善它。

1_thumb17

2. 玩具店SQL Server存储过程:该存储过程用来更新玩具商店的库存表,该存储过程需要4个参数,分别为productID、qty、storeNumberChangeType。通过ChangeType来判断是增加还是减小库存量。一个非常简单的存储过程,其T-SQL代码如下所示

USE [TailspinToys]
GO
/****** Object:  StoredProcedure [dbo].[sp_UpdateInventory]    Script Date: 07/14/2011 23:47:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_UpdateInventory]
	(
	@productID int =0,
	@qty int = 0,	
	@storeNumber int = 0,
	@bChangeType int = 1
)
	/*
	bChangeType :	0 = decrease
1 = increase			
	*/
AS
Declare @newQty int;
Declare @table varchar(50);
set @table = (SELECT TOP(1)
				[dbo].[Stores].[InventoryTableName] 
				FROM [dbo].[Stores]
				WHERE [dbo].[Stores].[StoreNumber] = @storeNumber);
set @table = lower(@table);
if @table = 'storeinventory_01' 
Begin
	if (@bChangeType = 1)
	begin
		--increase the qty
		set @newQty = (Select qty from dbo.StoreInventory_01 where ProductID = @ProductID)+ @qty
	end
	else
	begin
		--decrease the qty
		set @newQty = (Select qty from dbo.StoreInventory_01 where ProductID = @ProductID)- @qty
	end
	Update dbo.StoreInventory_01 
	 Set Qty=@newQty
	 Where (ProductID = @productID)
End
Else if @table = 'storeinventory_02' 
Begin
	if (@bChangeType = 1)
	begin
		--increase the qty
		set @newQty = (Select qty from dbo.StoreInventory_02 where ProductID = @ProductID)+ @qty
	end
	else
	begin
		--decrease the qty
		set @newQty = (Select qty from dbo.StoreInventory_02 where ProductID = @ProductID)- @qty
	end
	Update dbo.StoreInventory_02
	 Set Qty = @newQty
	 Where (ProductID = @productID)
End
Else if @table = 'storeinventory_03'
Begin
	if (@bChangeType = 1)
	begin
		--increase the qty
		set @newQty = (Select qty from dbo.StoreInventory_03 where ProductID = @ProductID)+ @qty
	end
	else
	begin
		--decrease the qty
		set @newQty = (Select qty from dbo.StoreInventory_03 where ProductID = @ProductID)- @qty
	end
	Update dbo.StoreInventory_03
	 Set Qty = @newQty
	 Where (ProductID = @productID)
End 
Else if @table = 'warehouse_inventory'
Begin
	if (@bChangeType = 1)
	begin
		--increase the qty
		set @newQty = (Select qty from dbo.Warehouse_Inventory where ProductID = @ProductID)+ @qty
	end
	else
	begin
		--decrease the qty
		set @newQty = (Select qty from dbo.Warehouse_Inventory where ProductID = @ProductID)- @qty
	end
	Update dbo.Warehouse_Inventory
	 Set Qty = @newQty
	 Where (ProductID = @productID)
End 
RETURN

3. 玩具店SQL Server数据库:目前该玩具店拥有4个仓储中心,这4个仓储的详细信息存储在dbo.Stores表中,并且每个仓储的库存信息存储分别存储在dbo.StoreInventory_01~04这4张表当中。

2_thumb12


使用WCF-SQL适配器调用SQL Server 存储过程

1. 生成调用UpdateInventory存储过程所需架构。打开Visual Studio,右键点击InventoryUpdate.Orchestration并选择添加生成的项,双击添加适配器元数据,在添加适配器向导界面中,从适配器列表下选择WCF-SQL,点击下一步

3_thumb8

2. 在使用适配器服务界面中,点击配置,在配置适配器窗口中,改变用户认证类型为Windows认证模式。切换到URI属性选项卡中,设置Server服务器名称为localhost,并将InitialCatalog数据库设置为TailspinToys,点击确定返回到使用适配器服务界面中。

4_thumb7

3. 返回到使用适配器服务界面中,点击连接按钮,待连接上数据库后,在选择类型下拉框中选择存储过程,在右侧的可选列表中,选择[dbo].[sp_UpdateInventory]并点击添加,设置文件名前缀为UpdateInventory,点击确定完成设置。

5_thumb8

4. 在Visual Studio中,双击UpdateInventory.xsd文件查看该架构,可以看到我们已经通过WCF-SQL适配器向导将数据库存储过程中所需的参数、请求消息、响应消息等都已经相应创建出来了。

6_thumb8

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值