SOA Patterns with BizTalk Server 2009 Implement SOA strategies for BizTalk Server solutions
Richard Seroter
BIRMINGHAM - MUMBAI
This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801
SOA Patterns with BizTalk Server 2009 Implement SOA strategies for BizTalk Server solutions Copyright © 2009 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers or distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: April 2009
Production Reference: 1200409
Published by Packt Publishing Ltd.
32 Lincoln Road
Olton
Birmingham, B27 6PA, UK.
ISBN 978-1-847195-00-5 www.packtpub.com
Cover Image by Vinayak Chittar (
[email protected])
This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801
Credits Author Richard Seroter Reviewers Charles Young
Production Editorial Manager Abhijeet Deobhakta Editorial Team Leader Akshara Aware
Ewan Fairweather Zach Bonham
Project Team Leader Lata Basantani
Acquisition Editor James Lumsden Development Editors Nikhil Bangera Siddharth Mangrole Technical Editor Gagandeep Singh Indexer Rekha Nair
Project Coordinator Neelkanth Mehta Proofreader Camille Guy Production Coordinator Shantanu Zagade Cover Work Shantanu Zagade
This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801
About the author Richard Seroter is a solutions architect for an industry-leading biotechnology
company, a Microsoft MVP for BizTalk Server, and a Microsoft Connected Systems Advisor. He has spent the majority of his career consulting with customers as they planned and implemented their enterprise software solutions. Richard worked first for two global IT consulting firms, which gave him exposure to a diverse range of industries, technologies, and business challenges. Richard then joined Microsoft as a SOA/BPM technology specialist where his sole objective was to educate and collaborate with customers as they considered, designed, and architected BizTalk solutions. One of those customers liked him enough to bring him onboard full time as an architect after they committed to using BizTalk Server as their enterprise service bus. Once the BizTalk environment was successfully established, Richard transitioned into a solutions architect role where he now helps identify enterprise best practices and applies good architectural principles to a wide set of IT initiatives. Richard maintains a semi-popular blog of his exploits, pitfalls, and musings with BizTalk Server and enterprise architecture at http://seroter.wordpress.com.
This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801
First off, I need to thank my exceptional technical reviewers and editors for doing such a fine job. Charles Young, Zach Bonham, and Ewan Fairweather all made significant contributions in their role as technical reviewers and this book is of a higher caliber as a result of their insight and wisdom. Tim Wieman also took time to review the book content and his real-world perspective was a welcome addition. I have to thank James Lumsden, Neelkanth Mehta, Nikhil Bangera, Gagandeep Singh and the whole top notch team from Packt Publishing for doing such a seamless job shepherding this book from inception through delivery. I'd have been much worse off in this endeavor without the assistance from Microsoft. Thanks to Richard Hughes and Emil Velinov for acting as facilitators to the Microsoft technical team and efficiently routing my questions to the appropriate individual. These capable Microsofties include Dmitri Ossipov, David Stucki, John Taylor, Sarathy Sakshi, and Rong Yu. I'm thankful every day that I work with some of the brightest and most creative technologists that you'll ever come across. They have contributed greatly to my architectural maturity and helped me (unwittingly or not!) craft many of the patterns that you'll find in this book. These people include my peerless manager Nancy Lehrer and colleagues Fred Stann, Ian Sutcliffe, Chris Allen, Simon Chatwin, Jaydev Thakkar, Elizabeth Waldorf, Felix Rabinovich, Aki Hayashi, and Victor Fehlberg. Finally, I had wondered before I wrote this book why everyone always thanks their families in a book's "acknowledgements" section. Now I know. I couldn't have gotten this task done without the support of my wife Amy and son Noah. Actually, Noah's too young to have put up a real fight, but he's a trooper nonetheless. Thanks you two for putting up with the late weeknights and stolen weekends. Hopefully my book residuals are enough to take us all to a nice dinner.
This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801
About the reviewers Charles Young has more than twenty years' experience of software architecture,
design, and implementation, and has worked on numerous projects as a developer, trainer, and consultant. He works as a Principal Consultant at Solidsoft, a UK-based company specializing in integration, workflow, and business process management on the Microsoft platform. Charles has wide experience of applying BizTalk Server, WCF, and WF to real-world problems. He has blogged extensively on the use of BizTalk Server and Business Rules, and is a regular speaker at architectural conferences and seminars.
Ewan Fairweather has worked for Microsoft for four years. He currently
works as a Program Manager in the BizTalk Product Group on the Customer Advisory Team (CAT). The BizTalk CAT is responsible for improving customer experience with BizTalk through: defining and delivering the enterprise services that the product requires, providing prescriptive guidance on best practices to all customers, and improving future versions of the product through customer feedback and key learnings. Prior to this, Ewan spent over three years working for Microsoft UK in the Premier Field Engineering team. In this role he worked with enterprise customers, helping them to maintain and optimize their BizTalk applications. This involved providing both proactive and reactive onsite assistance within the UK and the rest of Europe. Ewan has also worked in a dedicated capacity on some of the world’s largest BizTalk deployments, predominantly within financial services.
This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801
Ewan co-authored the successful Professional BizTalk Server 2006 book and has written many whitepapers for Microsoft including the Microsoft BizTalk Server Performance Optimization guide which is available on Microsoft’s MSDN website. Prior to joining Microsoft Ewan worked as a Cisco Certified Academy Instructor (CCAI) for a regional training organization delivering advanced routing and networking courses. Ewan holds a first class honors Bachelor of Science degree in Computing with Management from the University of Leeds. Outside of work, Ewan’s hobbies include reading, taking part in as many sports as possible, and regularly going to the gym.
Zach Bonham is a software developer working primarily with Microsoft's
connected systems technology. Zach is active in the Dallas/Fort Worth user group community and is a member of Microsoft's Connected Technologies Advisor Group. You can catch up with Zach at http://zachbonham.blogspot.com. I would like to thank Richard Seroter for taking the time to write this book as well as for his contributions to the online community. I would also like to thank Ray Crager for being the "smartest man alive" and a great teacher. There are an incredible number of BizTalk community members who need to be thanked, too many to list here, but you know who you are! Finally, I would like to thank my wife, Sally, and our two children for their love and support.
This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801
This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801
Table of Contents Preface Chapter 1: Building BizTalk Server 2009 Applications What is BizTalk Server? BizTalk architecture Setting up new BizTalk projects What are BizTalk schemas? Schema creation and characteristics Property schemas What are BizTalk maps? Configuring BizTalk messaging Working with BizTalk orchestration Summary
Chapter 2: Windows Communication Foundation Primer What is WCF? Defining the contract Service contracts Data contracts Implementing contracts in services Throwing custom service faults Choosing an endpoint address The role of service bindings Hosting services Consuming WCF services Non-WCF clients WCF clients Summary
1
9
9
14
19
21
22
25
26
27
30
32
33
33
34
35
36
38
40
41
42
43
47
48
51
53
This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801
Table of Contents
Chapter 3: Using WCF Services in BizTalk Server 2009 Relationship between BizTalk and WCF BizTalk WCF adapter Exposing WCF services from orchestrations Setting up the project Generating the WCF endpoint Configuring the Generated Components Anatomy of a generated WCF WSDL Exposing WCF services from schemas Consuming WCF services from orchestrations Consuming WCF services without orchestration Summary
Chapter 4: Planning Service-Oriented BizTalk Solutions The core principles of a service-oriented architecture Loosely coupled How does this apply to BizTalk Server solutions?
Abstraction
55
56
56
59
59
62
65
69
70
73
80
86
87
88
89
90
95
How does this apply to BizTalk Server solutions?
Interoperable
96
97
How does this apply to BizTalk Server solutions?
Reusable
100
102
How does this apply to BizTalk Server solutions?
Identifying Standard Message Exchange Patterns Request/Response services One-way services Request/Callback services Publish/Subscribe services Types of services RPC services Document services Event services Summary
Chapter 5: Schema and Endpoint Patterns Service-oriented schema patterns Designing schemas based on service type Canonical schemas Building and applying reusable schema components Node data type conversion for service clients Node feature mapping for service clients Element grouping Element properties
104
107
107
110
111
112
114
114
115
116
117
119
120
120
124
126
133
136
136
141
[ ii ]
This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801
Table of Contents Element restrictions
142
Exploiting generic schemas Service-oriented endpoint patterns Building reusable receive ports Constructing a contract-first endpoint Summary
Chapter 6: Asynchronous Communication Patterns Why asynchronous communication matters Using asynchronous services in WCF Creating the synchronous service Building a client-side asynchronous experience Working with server-side asynchronous services Using asynchronous services in BizTalk with WCF Consuming asynchronous services Exposing asynchronous services Getting results from asynchronous invocations Building WCF services that support client callbacks BizTalk support for client callbacks Using queues within asynchronous scenarios Summary
Chapter 7: Orchestration Patterns Why orchestration? What is MessageBox direct binding? Using dynamic service ports Defining the service Configuring IIS/WAS to host the service Building the BizTalk solution Configuring the BizTalk solution Supporting dual initiating message exchange patterns Building the BizTalk solution Configuring the BizTalk solution Chaining orchestrations using business rules Building the BizTalk solution The role of transactions in aggregated services Defining the service Building the BizTalk solution Building a Complex Event Processing solution Building the BizTalk solution Constructing the event schemas Building Pattern Matching Orchestrations
143
147
147
148
155
157
158
160
160
165
170
171
171
175
178
179
183
190
198
199
200
201
203
204
206
206
210
212
212
216
217
218
223
224
226
231
233
233
235
[ iii ]
This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801
Table of Contents
Constructing the complex event orchestration Summary
Chapter 8: Versioning Patterns
239
241
243
Why versioning? What service aspects may undergo changes? How to version schemas How to version endpoints Creating endpoints for custom WSDLs Versioning long-running orchestrations Techniques for delaying change Flexible fields Generic on-ramps Summary
Chapter 9: New SOA Capabilities in BizTalk Server 2009: WCF SQL Server Adapter What is the WCF SQL Adapter? Solution set up Executing composite transactions Polling for data Using SQL Server Query notification Consuming the adapter from outside BizTalk Server Called directly via WCF service reference Auto-generated IIS-hosted service Custom built proxy IIS-hosted service Summary
Chapter 10: New SOA Capabilities in BizTalk Server 2009: UDDI Services What is UDDI? How to add services to the UDDI registry Dynamic endpoint resolution via UDDI Building subscription alerts for service changes Summary
Chapter 11: New SOA Capabilities in BizTalk Server 2009:
ESB Guidance 2.0 What is ESB Guidance? Available services Transformation Services Resolver Services Exception Services
243
245
246
253
258
262
268
268
271
276
277
278
280
281
291
294
299
300
302
308
311
313
313
318
322
325
331
333
333
334
334
336
339
[ iv ]
This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801
Table of Contents
Itinerary Services Building a basic routing scenario Building a routing scenario with transformation Building a scenario with chained operations and orchestration Summary
Chapter 12: What's Next
346
348
353
356
367
369
"Dublin" What problem does it solve? .NET Services What problem does it solve? "Oslo" What problem does it solve? Future of BizTalk Server Summary
369
369
370
371
372
372
372
373
Index
375
[v]
This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801
This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801
Preface Repeat after me: SOA is something you do, not something you buy. -David Linthicum That may seem an odd quote to use when beginning a book about employing a particular product to facilitate the implementation of a service-oriented architecture (SOA). However, I think it sets the tone for what I'd like to accomplish here. There are countless books available on service-oriented architecture, and nearly as many independent definitions of what SOA actually is. Is it about web services, event-driven design, enterprise architecture, reusability, or maybe just a retread of existing object-oriented design? Depending on whom you ask, any of those preceding themes would be deemed correct. If you're looking to implement a SOA, you would find numerous vendors who claim to offer "SOA in a box" where becoming service oriented is as straightforward as installing a product. However, I prefer to define SOA as an architectural discipline based on loosely-coupled, autonomous chunks of business functionality, which can be used to construct composite applications. There are plenty of vital characteristics that can be teased out of that definition, but the most important point is that building a successful SOA requires an enterprise commitment and a particular way of thinking about software design, which cannot be achieved by simply hitching your wagon to the SOA product de jour. That said, a service-oriented architecture cannot be implemented using only high-minded strategies recorded with paper and pencil. It requires a technology solution that can realize the goals and vision of the business architecture. In this book, we're going to specifically investigate how to design and build service-oriented solutions using BizTalk Server 2009 as the host platform. The crop of high quality BizTalk Server books currently available all admirably cover the entire suite of capabilities which make up the product. And BizTalk by nature has many built-in service-oriented concepts such as loose coupling and message-oriented design, which are discussed in the existing books on hand. However, there is no book currently available that specifically looks at how to map service-oriented principles and patterns to the BizTalk product. That's where this book fits in.
This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801
Preface
One might look at Windows Workflow Foundation (WF) and Windows Communication Foundation (WCF) and ask why it matters to keep talking about BizTalk Server. Aren't these exciting technologies shepherding in a new era of Microsoft-based enterprise software design that makes a messaging bus like BizTalk obsolete? Fair question. Today, WF and WCF are foundational platform technologies on which future Microsoft applications will be built upon. They are both excellent at servicing particular problem areas around unified communication and workflow. BizTalk Server is Microsoft's enterprise class product, which enables process integration across disparate entities (such as organizations, platforms, applications) through a robust event-driven infrastructure that provides durable messaging, load balancing, and reliability. Similarly, while one can build a portal solution on top of Microsoft Internet Information Services (IIS) and ASP.NET technologies, the premier, complete portal offering from Microsoft is the SharePoint Server. I can attempt to build my own messaging solution using WCF and WF, but trying to design, build, and test such a solution takes me away from my primary goal of helping my organization solve business problems. What about the upcoming "Oslo" wave of products from Microsoft, which include the "Dublin" server, "Oslo" repository, and modeling toolset? The "Dublin" server, which fits into IIS and provides a powerful host for WCF and WF applications, solves specific problems around hosting and managing WCF and WF solutions. It is not a replacement of BizTalk Server and serves a different purpose. The "Oslo" modeling platform offers a compelling way to visualize solutions and construct rich models which can turn into actual applications. It is meant to solve problems around overall application design and does not provide any sort of infrastructure for actually running applications. Take a look at Chapter 12 for more about these upcoming technologies. Much has been written about the business aspect of SOA and achieving enterprise momentum for designing software in a service oriented fashion. If you are looking at how to engage your CEO or business stakeholders and expound on the virtues of SOA, this book is not your best resource. You will find that this book is a technical resource for folks looking to implement service-oriented patterns while exposing new services or consuming existing ones. We will take a deep look at how BizTalk Server works with the new WCF service model. We will also see how to take advantage of the BizTalk engine to build asynchronous processes and reusable orchestrations. This book, at its core, is an explanation of how to construct flexible solutions that are built for change.
[2]
This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801
Preface
Is BizTalk Server the only product that can help you reach a service-oriented nirvana? Of course not. You can very successfully build a SOA without using BizTalk Server, or any single product, for that matter. In fact, your SOA strategy should NOT be dependent on a single vendor or product, but rather support an ecosystem of service enabled platforms. This protects you from future change, while encouraging general SOA patterns that are not product-specific. That said, I plan to show you that BizTalk Server is an excellent platform for advancing your service-oriented architecture and creating new opportunities for making your environment more agile and flexible. As we work together through the examples in this book, I hope that you'll be able to visualize exactly how to utilize BizTalk Server in the most efficient manner within your organization's IT environment.
What this book covers This book is put together in a way that encourages you to follow along and build up your comfort level and knowledge as we progress from chapter to chapter. Throughout this book, I will make use of simple pharmaceutical scenarios to demonstrate key concepts. This industry is where I spend my time nowadays, and the demos that we build should have a common theme. That said, if you have no experience in the pharmaceutical industry, there's nothing to worry about. The examples we work through will involve basic "patient" and "drug evaluation trials" scenarios that are easily understood and don't distract from the underlying technology message. Chapters 1–3 are designed to introduce you to BizTalk and WCF and show you how to build a BizTalk services solution from scratch. This will help you keep up with the brisk pace of the later chapters. Chapters 4–12 build upon this knowledge and help you design and apply increasingly complex patterns and scenarios. In Chapter 1, we will look at what exactly BizTalk Server is, review the core architecture of the application, and show how to build an end-to-end solution. WCF is still a relatively new technology and many BizTalk customers are still comfortably using the classic ASP.NET web services framework. However, the future of the communication subsystem of Microsoft products is WCF, and it's an important technology to understand. In Chapter 2, we take a look at what problem WCF is attempting to solve, and how to actually build and host WCF services. After having a solid foundation on BizTalk and WCF, we will look at how to actually use services in the BizTalk environment. In Chapter 3, we build a number of common scenarios using BizTalk and WCF services. [3]
This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801
Preface
By Chapter 4, you will be comfortable with how BizTalk and WCF work, and how to build BizTalk solutions that take advantage of services. At this point it's crucial to investigate exactly what a service-oriented BizTalk solution looks like. What types of services should I expose? How can I exchange messages through the BizTalk bus? We'll answer these questions and much more at this stage of the book. A critical part of the technology portion of your service design is the contract definition. What are you sharing with the outside world? In addition to the contract, the actual transportation channel is a vital selection for your service. In Chapter 5, we will look at building service-oriented contracts and how to effectively work with BizTalk's service endpoints. BizTalk relies upon asynchronous communication, and in Chapter 6, we will look at how to take advantage of asynchronous messaging to build robust service-oriented solutions. We'll also cover the tricky concept of providing acknowledgements or results to clients that call services in a fire-and-forget fashion. You can use BizTalk orchestration to design new service logic or, build new composite applications based on existing services that have been discovered. In Chapter 7, we will look at how to build reusable orchestrations, accommodate transactions, and work with service aggregation. It's hard to build for change but it's a fact of life for every IT department. Fiddling with a service contract is a delicate operation, and in Chapter 8, we will investigate the options for minimizing the impact of service modifications. BizTalk Server 2009 offers a brand new WCF-based SQL Server adapter. In Chapter 9, we will investigate common usage patterns for polling data and updating data. Microsoft's UDDI Services have moved from being part of Windows Server to now being included only with BizTalk Server 2009. In Chapter 10, we will take a look at how to use the UDDI server to register and resolve services. Microsoft's Enterprise Service Bus Guidance is a key part of a service-oriented BizTalk solution and in Chapter 11, we will dig through the various components and build a series of examples. The Microsoft team responsible for BizTalk Server has an array of offerings on the upcoming slate. In Chapter 12, we will take a look at the role of .NET Services, what "Dublin" is, what's in store from "Oslo", and where BizTalk is heading in the future.
[4]
This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801
Preface
Who this book is for There are multiple target audiences for this book. First off, I'm writing this book as a resource for developers who have been tasked with building service-oriented BizTalk Server solutions. Developers will be able to use this book to implement common patterns to design services in way that fosters reuse and encourages flexibility. When developers are tasked with using BizTalk to consume existing services, they can also
use this book to review strategies and considerations they need to take into account.
This book is also targeted at architects, who are responsible for envisioning an
enterprise solution and implementing the software blueprint. We will cover a variety
of ways to use BizTalk in a service-oriented fashion that will help architects decide
the best way to distribute the system processing.
As I mentioned earlier, this book is not a pure tutorial on BizTalk Server or WCF.
So, I'll expect that you are somewhat familiar with BizTalk Server 2006 development,
and have seen a WCF service in action before.
Also, I'll be spending plenty of time using Visual Studio.NET to demonstrate
development tasks, so it would be useful if you have used Microsoft's development
environment in the past.
That said, I will be providing a brief overview of both BizTalk Server and WCF, so
if you are new to either, or both, I'd like to think that you will still find this book a valuable resource in your library.
Conventions In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning. Code words in text are shown as follows: "The next thing to do is to delete the Address node." A block of code will be set as follows: [XmlElementAttribute("FailureScreen", typeof(FailureScreen)] [XmlElementAttribute("StandardScreen", typeof(StandardScreen)] public object Item { get { return this.itemField; } set { this.itemField = value; } } [5]
This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801
Preface
When we wish to draw your attention to a particular part of a code block, the relevant lines or items will be shown in bold: public bool BuyThisBook(int copies) {
if(copies