What we will coverWhat we will cover
COM+ COM+ 的概念及优点的概念及优点 Microsoft .NET / COM+ Microsoft .NET / COM+ 连接连接 更强的服务及架构更强的服务及架构
Session PrerequisitesSession Prerequisites
Level 200Level 200
Visual BasicVisual Basic®® .NET or C# .NET or C# 的使用经验的使用经验 熟悉数据库事务熟悉数据库事务 不需要任何有关不需要任何有关 COMCOM 的经验的经验
Key MessagesKey Messages
Microsoft .NET Microsoft .NET 在企业服务上依靠于 在企业服务上依靠于 COM+COM+
执行简单好处多执行简单好处多 比重新开发一遍代码更划算比重新开发一遍代码更划算
DemonstrationsDemonstrations
COM+ COM+ 服务管理代码服务管理代码 隔离级别 和无组件的隔离级别 和无组件的 COM+COM+ 服务服务 队列组件队列组件
AgendaAgenda
COM+ COM+ 服务服务 管理代码管理代码 COM+ 1.5 COM+ 1.5 增强增强 更强的 更强的 COM+ COM+ 服务服务
COM+ ServicesCOM+ ServicesOverviewOverview
企业服务架构及运行时企业服务架构及运行时 过去的技术过去的技术
COMCOM Microsoft Transaction Server (MTS)Microsoft Transaction Server (MTS) COM+ 1.0COM+ 1.0
更强的管理界面更强的管理界面 组件服务组件服务 管理 管理 APIAPI
COM+ ServicesCOM+ ServicesBenefitsBenefits
可靠性可靠性————事务的应用事务的应用 规模性规模性————对象池以及即时活动的应用对象池以及即时活动的应用 灵活性灵活性————松散耦合事件松散耦合事件 批处理和组件队列保证消息传递批处理和组件队列保证消息传递 简单执行简单执行————通过服务而不是组件通过服务而不是组件
COM+ ServicesCOM+ ServicesTransactionsTransactions
对组件提供事务性上下文对组件提供事务性上下文 组件说明自己的事务性需求组件说明自己的事务性需求 在一个事务中可以包含多个组件在一个事务中可以包含多个组件 自动的提交或回滚自动的提交或回滚
COM+ ServicesCOM+ ServicesTransactionsTransactions
BB
DBDB
DBDB
AA
MSMQMSMQCC
COM+ ServicesCOM+ ServicesJust-In-Time ActivationJust-In-Time Activation
客户端请求前服务器资源始终是可用的客户端请求前服务器资源始终是可用的 增加规模性增加规模性
返回调用之后变为不活动的状态返回调用之后变为不活动的状态 资源回收资源回收 客户端认为所有对象都是活动的客户端认为所有对象都是活动的
仅在方法调用时变为活动的仅在方法调用时变为活动的 使用无状态对象使用无状态对象
COM+ ServicesCOM+ ServicesObject PoolingObject Pooling
内存中的对象实例池内存中的对象实例池 客户端请求客户端请求
在可用的情况下从池中返回实例在可用的情况下从池中返回实例 客户端请求一直被阻止直到实例可用或超时时客户端请求一直被阻止直到实例可用或超时时
对对 “ “昂贵的昂贵的” ” 对象使用对象池对象使用对象池 创建创建 获取获取
COM+ ServicesCOM+ ServicesObject PoolingObject Pooling
最大最大 // 最小设置最小设置 减少相应时间减少相应时间
更高的最小值更高的最小值 减少最大请求数量减少最大请求数量
降低最大值降低最大值
AgendaAgenda
COM+ COM+ 服务服务 管理代码管理代码 COM+ 1.5 COM+ 1.5 增强增强 更强的更强的 COM+ COM+ 服务服务
Managed CodeManaged CodeSystem.EnterpriseServicesSystem.EnterpriseServices
MTS MTS 和 和 COM+COM+ 的后续支持的后续支持 提供以下支持提供以下支持
分布式事务分布式事务 Just-In-Time activationJust-In-Time activation 对象池对象池 安全性安全性 队列组件队列组件 松散耦合事件松散耦合事件 服务应用程序处理模式服务应用程序处理模式
Managed CodeManaged CodeProgramming ModelProgramming Model
public class AccountClient
private void btnTransactions_Click() { Account acc = New Account(); acc.Credit() }}
Managed CodeManaged CodeProgramming ModelProgramming Model
using System;using System.EnterpriseServices;[assembly : ApplicationName("TxDemo")] [TransactionAttribute()]public class Account : ServicedComponent { [AutoCompleteAttribute()] public void Credit() { // do some work }}
Managed CodeManaged CodeAssembly AttributesAssembly Attributes
ApplicationNameAttributeApplicationNameAttribute ApplicationIDAttributeApplicationIDAttribute ApplicationActivationAttributeApplicationActivationAttribute ApplicationAccessControlAttributeApplicationAccessControlAttribute ApplicationQueuingAttributeApplicationQueuingAttribute
Managed CodeManaged CodeClass AttributesClass Attributes
TransactionAttributeTransactionAttribute JustInTimeActivationAttributeJustInTimeActivationAttribute ObjectPoolingAttributeObjectPoolingAttribute PrivateComponentAttributePrivateComponentAttribute ComponentAccessControlAttributeComponentAccessControlAttribute SecurityRoleAttributeSecurityRoleAttribute EventClassAttributeEventClassAttribute InterfaceQueuingAttributeInterfaceQueuingAttribute
Managed CodeManaged CodeRegistrationRegistration
必须注册在必须注册在 COM+ COM+ 目录中目录中 创建创建 COM+ COM+ 应用应用 安装组件安装组件 配置组件配置组件
自动注册自动注册 RegSvcs.exeRegSvcs.exe RegistrationHelper RegistrationHelper 类类
Managed CodeManaged CodeRegistrationRegistration
CLR / Dynamic CLR / Dynamic registrationregistration RegistrationHelperRegistrationHelper
RegSvcs.exeRegSvcs.exe
Your admin Your admin codecode
COM+ COM+ catalogcatalog
AssemblyAssembly
Demonstration 1Demonstration 1COM+ ServicesCOM+ Services
In Managed CodeIn Managed Code
TransactionsTransactionsRegistrationRegistration
AgendaAgenda
COM+ COM+ 服务服务 管理代码管理代码 COM+ 1.5 COM+ 1.5 增强增强 更强的更强的 COM+ COM+ 服务服务
COM+ 1.5 EnhancementsCOM+ 1.5 EnhancementsIsolation LevelIsolation Level
管理并发的数据访问管理并发的数据访问 使用使用 SQL SQL 语句语句 可配置可配置
组件服务组件服务 TransactionAttributeTransactionAttribute
[Transaction(Isolation=TransactionIsolationLevel.ReadUncommitted)]
COM+ 1.5 EnhancementsCOM+ 1.5 EnhancementsIsolation LevelIsolation Level
Insert…Insert…John DoeJohn Doe
123 Main St.123 Main St.Redmond, WARedmond, WA
Select …Select …Where State = WAWhere State = WA
COM+ 1.5 EnhancementsCOM+ 1.5 EnhancementsIsolation LevelIsolation Level
默认为串行默认为串行 安全但是受限制安全但是受限制 会降低性能会降低性能
降低隔离级别降低隔离级别 潜在的可以增加并发、性能以及规模潜在的可以增加并发、性能以及规模 会导致读脏数据会导致读脏数据
COM+ 1.5 EnhancementsCOM+ 1.5 EnhancementsServices Without ComponentsServices Without Components
Transactions without ServicedComponentTransactions without ServicedComponent More implementation optionsMore implementation options
ServiceConfigServiceConfig Set context options like IsolationLevel and Set context options like IsolationLevel and
TransactionTimeoutTransactionTimeout
ServiceDomainServiceDomain Enter and leave transactionEnter and leave transaction Query transaction resultQuery transaction result
ContextUtilContextUtil Vote with SetComplete and SetAbortVote with SetComplete and SetAbort
COM+ 1.5 EnhancementsCOM+ 1.5 EnhancementsServices Without ComponentsServices Without Components
ServiceConfig config = new ServiceConfig();
config.Transaction = TransactionOption.RequiresNew;config.TransactionTimeout = 30;config.IsolationLevel = TransactionIsolationLevel.ReadUncommitted;
ServiceDomain.Enter(config);
COM+ 1.5 EnhancementsCOM+ 1.5 EnhancementsServices Without ComponentsServices Without Components
…ServiceDomain.Enter(config);try{ sqlCom1.ExecuteNonQuery(); sqlCom2.ExecuteNonQuery(); ContextUtil.SetComplete();}catch{ ContextUtil.SetAbort();}TransactionStatus s = ServiceDomain.Leave();
COM+ 1.5 EnhancementsCOM+ 1.5 EnhancementsPrivate ComponentsPrivate Components
COM+ 1.0COM+ 1.0 所有组件都是公共的所有组件都是公共的
COM+ 1.5COM+ 1.5 可配置组件的作用域可配置组件的作用域 Public—Public— 其他应用程序可用其他应用程序可用 Private—Private— 仅同一个应用程序可用仅同一个应用程序可用
Demonstration 2Demonstration 2COM+ 1.5 EnhancementsCOM+ 1.5 Enhancements
Isolation LevelIsolation LevelServices Without ComponentsServices Without Components
AgendaAgenda
COM+ COM+ 服务服务 管理代码管理代码 COM+ 1.5 COM+ 1.5 增强增强 高级 高级 COM+ COM+ 服务服务
Advanced COM+ ServicesAdvanced COM+ ServicesProcess InitializationProcess Initialization
获取获取 COM+ COM+ 应用程序启动和关闭事件应用程序启动和关闭事件 IProcessInitializer IProcessInitializer 接口接口
启动启动 所有工作必须在所有工作必须在 9090 秒内完成秒内完成
关闭关闭 不保证序列不保证序列 实例运行在应用程序中实例运行在应用程序中
Advanced COM+ Services Advanced COM+ Services Queued ComponentsQueued Components
异步组件调用的架构异步组件调用的架构 MSMQ MSMQ 提供传输的可靠性提供传输的可靠性 增加客户端性能增加客户端性能
不依靠于应用程序的可靠性不依靠于应用程序的可靠性 立刻返回调用立刻返回调用
增加服务器性能增加服务器性能 更短的组件生存周期更短的组件生存周期 有计划的批处理有计划的批处理
ClientClient
Advanced COM+ Services Advanced COM+ Services Queued ComponentsQueued Components
ServerServer
QueueQueue
ComponentComponent
Listener / PlayerListener / Player
AppApp
RecorderRecorder
Method CallMethod Call
Call ReturnCall Return
Method CallMethod Call
Advanced COM+ Services Advanced COM+ Services Queued ComponentsQueued Components
InterfaceQueuingAttributeInterfaceQueuingAttribute Class levelClass level Identifies what interfaces to expose for Identifies what interfaces to expose for
queuingqueuing
ApplicationQueuingAttributeApplicationQueuingAttribute Assembly levelAssembly level Notifies COM+ to create and activate a Notifies COM+ to create and activate a
listenerlistener
Advanced COM+ Services Advanced COM+ Services Queued ComponentsQueued Components
Client uses Marshal.BindToMoniker with Client uses Marshal.BindToMoniker with COM moniker to get object referenceCOM moniker to get object reference
IFoo iQc = null;string m = "queue:/new:MyApp.Bar"
iQc=(IFoo)Marshal.BindToMoniker(m);
Advanced COM+ Services Advanced COM+ Services Loosely Coupled EventsLoosely Coupled Events
后期消息绑定模型的事件发布后期消息绑定模型的事件发布 多对多的发布多对多的发布 发布者和订阅者通过事件类绑定,而不是相发布者和订阅者通过事件类绑定,而不是相互绑定互绑定
COM+ COM+ 管理订阅管理订阅 Component ServicesComponent Services COM+ APICOM+ API
COM+COM+Event ClassesEvent Classes
SubscriptionsSubscriptions
Register EventRegister Event
Add SubscriptionAdd Subscription
Advanced COM+ Services Advanced COM+ Services Loosely Coupled EventsLoosely Coupled Events
SubscriberSubscriber
CustomSinkCustomSink
CustomEventCustomEvent
CustomEventCustomEvent
CustomSinkCustomSink
PublisherPublisher
CustomEvent ec = new CustomEvent();ec.SomeEvent();
Advanced COM+ Services Advanced COM+ Services Loosely Coupled EventsLoosely Coupled Events
持续持续 / / 短暂订阅短暂订阅 事件队列事件队列 并行执行并行执行 事件过滤事件过滤
Demonstration 3Demonstration 3Queued ComponentsQueued Components
Creating a Queued ComponentCreating a Queued ComponentCalling a Queued ComponentCalling a Queued Component
Session SummarySession Summary
使用 使用 COM+ COM+ 服务服务 Increase reliabilityIncrease reliability Increase scalabilityIncrease scalability Increase flexibilityIncrease flexibility
EnterpriseServicesEnterpriseServices 通过属性实现更加简单通过属性实现更加简单
For More Information…For More Information…
MSDN Web site at MSDN Web site at msdn.microsoft.commsdn.microsoft.com
Writing Serviced ComponentsWriting Serviced Components http://msdn.microsoft.com/library/en-us/cphttp://msdn.microsoft.com/library/en-us/cp
guide/html/cpconwritingservicedcomponenguide/html/cpconwritingservicedcomponents.aspts.asp
COM+ Services Without ComponentsCOM+ Services Without Components http://msdn.microsoft.com/library/http://msdn.microsoft.com/library/
default.asp?url=/library/en-us/cossdk/default.asp?url=/library/en-us/cossdk/htm/htm/pgservices_serviceswithoutcomponents_7pgservices_serviceswithoutcomponents_7u5v.aspu5v.asp
Training & Training & EventsEvents
MSDN Webcasts, MSDN Online MSDN Webcasts, MSDN Online Seminars, Tech-Ed, PDC, Developer DaysSeminars, Tech-Ed, PDC, Developer Days
MSDNMSDNEssential Resources for DevelopersEssential Resources for Developers
Subscription Subscription ServicesServices
OnlineOnlineInformationInformation
MembershipMembershipProgramsPrograms
Print Print PublicationsPublications
Library, OS, Professional, Enterprise, Library, OS, Professional, Enterprise, Universal Delivered via CD-ROM, DVD, WebUniversal Delivered via CD-ROM, DVD, Web
MSDN Online, MSDN Flash, How-To MSDN Online, MSDN Flash, How-To Resources, Download CenterResources, Download Center
MSDN User GroupsMSDN User Groups
MSDN MagazineMSDN MagazineMSDN NewsMSDN News
How-To ResourcesHow-To ResourcesSimple, Step-By-Step ProceduresSimple, Step-By-Step Procedures Embedded Development How-To ResourcesEmbedded Development How-To Resources General How-To Resources General How-To Resources Integration How-To Resources Integration How-To Resources JScriptJScript®® .NET How-To Resources .NET How-To Resources .NET Development How-To Resources .NET Development How-To Resources Office Development Resources Office Development Resources Security How-To Resources Security How-To Resources Visual BasicVisual Basic®® .NET How-To Resources .NET How-To Resources Visual C#Visual C#™™ .NET How-To Resources .NET How-To Resources Visual StudioVisual Studio®® .NET How-To Resources .NET How-To Resources Web Development How-To Resources (ASP, IIS, XML) Web Development How-To Resources (ASP, IIS, XML) Web Services How-To Resources Web Services How-To Resources Windows Development How-To Resources Windows Development How-To Resources
http://msdn.microsoft.com/howtohttp://msdn.microsoft.com/howto
MSDN WebcastsMSDN WebcastsInteractive, Live Online EventInteractive, Live Online Event
Interactive, synchronous, live online Interactive, synchronous, live online eventevent
Discuss the hottest topics from MicrosoftDiscuss the hottest topics from Microsoft Open and free for the general publicOpen and free for the general public Held each weekHeld each week
http://www.microsoft.com/usa/webcastshttp://www.microsoft.com/usa/webcasts
MSDN Subscriptions MSDN Subscriptions THE way to get Visual Studio .NETTHE way to get Visual Studio .NETVisual Studio .NETVisual Studio .NET MSDN SubscriptionsMSDN Subscriptions
NE
W
ProfessionalProfessional• Tools to build applications Tools to build applications
and XML Web services for and XML Web services for Windows and the WebWindows and the Web
MSDN ProfessionalMSDN Professional$1199 new$1199 new
$899 renewal/upgrade$899 renewal/upgrade
MSDN EnterpriseMSDN Enterprise$2199 new$2199 new
$1599 renewal/upgrade$1599 renewal/upgrade
MSDN UniversalMSDN Universal$2799 new$2799 new
$2299 renewal/upgrade$2299 renewal/upgrade
Enterprise DeveloperEnterprise Developer• Enterprise lifecycle toolsEnterprise lifecycle tools• Team development supportTeam development support• Core Windows Server Core Windows Server
SystemSystem™™ family members family members
Enterprise ArchitectEnterprise Architect• Software and data modelingSoftware and data modeling• Enterprise templatesEnterprise templates• Architectural guidanceArchitectural guidance
Where Can I Get MSDN?Where Can I Get MSDN?
Visit MSDN Online atVisit MSDN Online atmsdn.microsoft.commsdn.microsoft.com
Register for the MSDN Flash e-mail Register for the MSDN Flash e-mail newsletter at newsletter at
msdn.microsoft.com/flashmsdn.microsoft.com/flash Become an MSDN CD subscriber at Become an MSDN CD subscriber at
msdn.microsoft.com/subscriptionsmsdn.microsoft.com/subscriptions MSDN Online SeminarsMSDN Online Seminars
msdn.microsoft.com/training/seminarsmsdn.microsoft.com/training/seminars Attend more MSDN eventsAttend more MSDN events
Microsoft PressMicrosoft PressEssential Resources for DevelopersEssential Resources for Developers
MicrosoftMicrosoft®® Visual Studio Visual Studio®® .NET is here! .NET is here!This is your chance to start building the next big This is your chance to start building the next big
thing. Develop your .NET skills, increase your thing. Develop your .NET skills, increase your productivity with .NET books from Microsoftproductivity with .NET books from Microsoft®® Press Press
www.microsoft.com/mspresswww.microsoft.com/mspress
Become A Microsoft Certified Become A Microsoft Certified Solution DeveloperSolution Developer
What Is MCSD?What Is MCSD? Premium certification for professionals who design Premium certification for professionals who design
and develop custom business solutions.and develop custom business solutions. How Do I attain MCSD Certification?How Do I attain MCSD Certification?
It requires passing four exams to prove It requires passing four exams to prove competency with Microsoft solution architecture, competency with Microsoft solution architecture, desktop applications, distributed application desktop applications, distributed application development, and development tools.development, and development tools.
Where Do I Get More Information?Where Do I Get More Information? For more information about certification For more information about certification
requirements, exams, and training options, requirements, exams, and training options, visit visit www.microsoft.com/mcpwww.microsoft.com/mcp..
TrainingTrainingTraining Resources for DevelopersTraining Resources for Developers Course Title:Course Title:
Course Number:Course Number: Availability:Availability: Detailed Syllabus: Detailed Syllabus: www.microsoft.com/traincertwww.microsoft.com/traincert
Course Title:Course Title: Course Number:Course Number: Availability:Availability: Detailed Syllabus: Detailed Syllabus: www.microsoft.com/traincertwww.microsoft.com/traincert
To locate a training provider for this course, please accessTo locate a training provider for this course, please access
www.microsoft.com/traincert Microsoft Certified Technical Education Centers Microsoft Certified Technical Education Centers
are Microsoft premier partners for training servicesare Microsoft premier partners for training services
© 2003 Microsoft Corporation. All rights reserved.Microsoft, MSDN, Windows, Windows Server, Windows Server System, Visual Basic, Visual Studio, Microsoft Press, and SQL Server are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. The names of actual companies and products mentioned herein may be the trademarks of their respective owners. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.