Www Xddl Info Introducing Dot Net_3 doc

45 236 0
Www Xddl Info Introducing Dot Net_3 doc

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

CHAPTER 6  WINDOWS WORKFLOW FOUNDATION 4 147 Figure 6-13. New flowchart workflow 3. The design view for flowcharts looks slightly different than sequential workflows. The green circle indicates where the workflow starts. We need to create a new activity to read input from the user. Create a new class called ReadInput. 4. Enter the following using statement: using System.Activities; 5. Now enter the following code: public class ReadInput : CodeActivity<Int32> { protected override Int32 Execute(CodeActivityContext context) { return Convert.ToInt32(Console.ReadLine()); } } 6. Save the class and compile the application. 7. Open Workflow1.xaml. 8. Drag a WriteLine activity beneath the green circle and change the Display Name to “What is your age?” and set the Text to “What is your age?” CHAPTER 6  WINDOWS WORKFLOW FOUNDATION 4 148 9. Drag the new ReadInput activity beneath the “What is your age?” activity and change the display name to “Read input.” 10. Create a new variable called age of type Int32. 11. On the ReadInput activity, set the Result property to age. The next thing to do is determine if the customer is old enough to see the film (which in this case will always have an 18 rating). Flow chart workflows have a new type of activity not found in sequential workflows, called FlowDecision. 1. Drag a FlowDecision activity beneath the read input block and change the condition to Age >= 18. There are obviously two possibilities to this expression: • Customer is old enough so they can see the film (FlowDecision condition = true). • Customer is too young, so shouldn’t be seeing any movies (FlowDecision condition = false). 2. To simulate the customer failing age verification, drag a WriteLine activity to the right of the flow decision and change the display name and text to “Sorry not old enough.” 3. Drag another WriteLine activity beneath the flow decision and change the display name and text to “Age validation successful.” 4. We now need to link up the activities we have just created. Move the mouse over the green circle that indicates the start of the flow chart workflow, and three grey dots will appear around it. Click the one on the bottom of the circle and then drag the mouse down to the ReadInput activity. 5. When you near the WriteLine activity, three grey dots will appear around it. Drag the line to one of these dots and then release the mouse button to link up the start of the workflow with our read line activity. 6. Link up the “What is your age?” and ReadInput activities. 7. We need to join the FlowDecision up to the workflow. FlowDecision activities have two nodes, true or false, that surprisingly indicate the path to take when the condition specified is true or false. Drag the false node to the “Sorry not old enough” WriteLine activity and then drag another line from “Sorry not old enough” back round to the ReadInput activity. 8. Drag the true node on the FlowDecision activity to the “Age validation successful” activity. 9. Finally drag a line between the “What is your age?” and ReadInput activity. Your final work flow should look like Figure 6-14. 10. Open Program.cs and add a Console.ReadKey(); beneath the invoke command so the application doesn’t close immediately. 11. That’s it; your workflow is ready to run. Press F5 to run it. 12. Try entering different ages and note that unless you enter at least 18 the workflow will write “Sorry not old enough.” CHAPTER 6  WINDOWS WORKFLOW FOUNDATION 4 149 Figure 6-14. Final age validation work flow WCF/Messaging Improvements A number of enhancements have been introduced in WF4 to improve integration with WCF and to ease messaging scenarios. Correlation Correlation functionality first appeared in WF3.5 and allows you to route incoming messages to specific workflow instances based on their content or protocol used. For example if you have a very long running workflow where replies take weeks or months to return it is important that when a reply is received it is sent to the correct individual workflow. ReceiveAndSendReply and SendAndReceiveReply are the new activities discussed in the following sections that provide a correlated send and receive activities with a number of new methods of correlation such as xpath and correlation scope. WCF Workflow Service Applications WCF Workflow Service applications are a new type of project in VS2010 that make it very easy to create workflows for sending and receiving data. They essentially provide a declarative WCF service defined CHAPTER 6  WINDOWS WORKFLOW FOUNDATION 4 150 using workflow activities. WCF Workflow Service applications have all the benefits of WF such as support for long-running services, GUI interface, and also the additional benefits that as they are declared declaratively so are easy to deploy and version. VS2010 comes with a WCF Workflow Service Application template that you can adapt for your own needs. The sample application simply echoes a number you send to it back to you. Let’s take this for a spin now. 1. Create a new WCF Workflow Service project called Chapter6.WFService. The template will contain a sequential activity looking very similar to Figure 6-15. Figure 6-15. WF Service project 2. This sequential activity is defined in the file Service1.xamlx. If you open this up with the XML editor you will see the XAML that defines this service (boring bits removed as it's pretty long): <p:Sequence DisplayName="Sequential Service" sad:XamlDebuggerXmlReader.FileName="D:\wwwroot\book\Chapter6_WF\Chapter6.WFService\Cha pter6. WFService\Service1.xamlx"> <p:Sequence.Variables> <p:Variable x:TypeArguments="CorrelationHandle" Name="handle" /> <p:Variable x:TypeArguments="x:Int32" Name="data" /> </p:Sequence.Variables> CHAPTER 6  WINDOWS WORKFLOW FOUNDATION 4 151 <Receive x:Name="__ReferenceID0" DisplayName="ReceiveRequest" OperationName="GetData" ServiceContractName="contract:IService" CanCreateInstance="True"> <Receive.CorrelationInitializers> <RequestReplyCorrelationInitializer CorrelationHandle="[handle]" /> </Receive.CorrelationInitializers> <ReceiveMessageContent> <p:OutArgument x:TypeArguments="x:Int32">[data]</p:OutArgument> </ReceiveMessageContent> </Receive> <SendReply Request="{x:Reference Name=__ReferenceID0}" DisplayName="SendResponse" > <SendMessageContent> <p:InArgument x:TypeArguments="x:String">[data.ToString()]</p:InArgument> </SendMessageContent> </SendReply> </p:Sequence> </WorkflowService> 3. As the template service doesn’t do anything apart from echo a value back, we are going to modify it slightly so we can see a change. In the SendResponse box click the Content text box and amend the Message data property to the following: data.ToString() + " sent from WF service" 4. Click OK. 5. Save the project. 6. Now add a new console application to the solution called Chapter6.WFServiceClient. 7. Add a service reference to Chapter6.WFService (click Add Service Reference then DiscoverServices in Solution; it will be listed as Service1.xamlx). 8. Leave the namespace as ServiceReference1. 9. In Chapter6.WFServiceClient modify Program.cs to the following: ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient(); Console.WriteLine(client.GetData(777)); Console.ReadKey(); 10. Set Chapter6.WFServiceClient as the startup project and press F5 to run. You should see the message “777 sent from WF Service” output to the console. If you wanted to deploy this service, you could simply copy the the Service1.xamlx and Web.config file to a web server or even host it using “Dublin.” Activities A number of new activities are introduced in WF4, and some activities from WF3 have been dropped. Note the Microsoft upgrade documents mentioned at the start of this chapter contain more detail on these changes and suggest an upgrade path. CHAPTER 6  WINDOWS WORKFLOW FOUNDATION 4 152 WF3 Activity Replacements Some existing WF3 activites have now been dropped. The suggested replacements are listed below: • IfElse becomes If or Switch. • Listen becomes Pick. • Replicator becomes ForEach or ParallelForEach. • CodeActivity is gone and you should use activity customization as described above. New Activities WF4 introduces a number of new activities. AddToCollection, RemoveFromCollection, ExistsInCollection & ClearCollection Activities for working with collections in your workflows. Assign Assign allows us to assign values to variables and arguments and has been used extensively in the previous examples. CancellationScope CancellationScope allows you to specify activities to be run should an activity be cancelled. The body section surrounds the code you may wish to cancel and the cancellation handler section specifies code to run if an activity is cancelled. See Figure 6-16. Figure 6-16. CancellationScope CHAPTER 6  WINDOWS WORKFLOW FOUNDATION 4 153 CompensatableActivity An advanced activity used for long running workflows that allows you to define compensation, confirmation, and cancellation handlers for an activity. This is used in conjunction with the compensate and confirm activities. DoWhile DoWhile continues to run code until the condition specified is true. The code inside it will be run at least once. See Figure 6-17. Figure 6-17. DoWhile ForEach An activity for looping round a collection. Interop Interop allows you to use your existing WF3 activities and workflow in a WF4 application. Interop can wrap any non-abstract types inherited from System.Workflow.ComponentModel.Activity. Any properties are exposed as arguments to WF4. Interop can help migration from WF3 or allow you to use existing WF3 workflows you don’t possess the source to. InvokeMethod InvokeMethod allows the calling of an existing static method. You can pass generic types, pass parameters by reference and also call it asynchronously. CHAPTER 6  WINDOWS WORKFLOW FOUNDATION 4 154 Parallel Parallel activity was present in WF3, but didn’t truly run activities in parallel (it used time slicing). In WF4 the Parallel activity and ParallelForEach the activities now run truly in parallel subject to suitable hardware. Persist Persist allows you to persist the workflow instance using the current workflow configuration settings. You can also specify areas where state should not be persisted with no-persist zones. Pick Provides functionality for using events and replaces WF3s listen activity. ReceiveAndSendReply and SendAndReceiveReply WF4 has improved support for messaging scenarios by introducing a number of new activities for sending and receiving data between applications and improved support for correlating messages. WF4 introduces the ReceiveAndSendReply (Figure 6-18) and SendAndReceiveReply (correlated versions of Send and Receive) activities that allow you to specify code to run in between the initial Send or receive. Figure 6-18. ReceiveAndSendReply CHAPTER 6  WINDOWS WORKFLOW FOUNDATION 4 155 These are advanced activities so please see the WF SDK for an example of their usage. The messaging activities can operate with the following types of data: • Message • MessageContracts • DataContracts • XmlSerializable TryCatch TryCatch allows you to specify activities to be performed should an exception occur and code that should always run in a Finally block similar to C# or VB.NET. See Figure 6-19. Figure 6-19. TryCatch Switch<T> and FlowSwitch Switch is similar to the switch statement in C# and contains an expression and a set of cases to process. FlowSwitch is the flowchart equivalent of the switch statement. See Figure 6-20. CHAPTER 6  WINDOWS WORKFLOW FOUNDATION 4 156 Figure 6-20. Switch Powershell and Sharepoint Activities In the preview versions of WF4, you may have seen Powershell, Sharepoint, and Data activities. These are now moved to the workflow SDK because Microsoft has a sensible rule for framework development that .NET should not have any dependencies on external n external technologies. Misc Improvements WF 4 also contains a number of other enhancements. • WF version 4 is 10 to 100 times faster than WF3, and performance of the WF designer is much improved. • Programming model has been simplified. • Expressions now have intellisense (which can be utilized by activities you create as well). • WF4 has support for running workflows in partial trust environments. • Improved support for declarative (XAML only) workflows. • Add breakpoints can be added to XAML directly. If breakpoints are added in design view and you switch to XAML view they will be shown (and vice versa). See Figure 6-21. [...]... contained within WCF4 Table 7-2 Standard Endpoint Types Na me Des cripti on announcementEndpoint Used to send announcments discoveryEndpoint Used for service discovery dynamicEndpoint No info at time of writing mexEndpoint Metadata information udpAnnouncementEndpoint Used to send announcement messages over UDP multicast binding udpDiscoveryEndpoint Discovery operations over UDP multicast binding webHttpEndpoint... notified when specific events occur in your workflows Profiles can be created programmatically or through the configuration file and you have fine-grained control over the level of detail returned For more information please refer to: http://blogs.msdn.com/endpoint/archive/ 2009/06/19/workflow-tracking-profiles-in-net-4-0-beta-1.aspx • Run your workflows on “Dublin” or Azure platform (see Chapters 7 and... endpoint address) • Your own filters This example shows the creation of an ActionMessage filter that would be added to the entries section: Multicast Support You can use the new routing functionality to multicast messages by creating filters that will be matched multiple times with different endpoints For example, we... WS-Discovery was originally developed as joint venture between BEA Systems, Canon, Intel, Microsoft, and WebMethods, and is famously used in Windows Vista to provide the “people near me” functionality For more information on WS-Discovery please refer to http://schemas.xmlsoap.org/ws/2004/10/ discovery/ws-discovery.pdf WS-Discovery is a great way of easing deployment of your applications, and perhaps even making... WS-Discovery can operate in two different modes: managed and adhoc Managed Mode In managed mode, a list of services is held in a central location (called the discovery proxy) When services start up, they inform the discovery proxy of their location Managed mode is more complex to implement than adhoc, but it creates much less network traffic and is more suitable for use in larger networks It does, however,... OnlineAnnouncementReceived and OfflineAnnouncementReceived events 169 CHAPTER 7 WINDOWS COMMUNICATION FOUNDATION WCF Starter Kit Integration Two great features previously seen in the WCF REST starter kit (http:/ /www. asp.net/downloads/starterkits/wcf-rest/) have been brought into WCF4: • Help pages • HTTP caching Help Pages Help pages are automatically generated HTML pages that describe how to call your service... processing messages that makes a queue item invisible to other consumers and creates a transaction for performing work on it that if rolled back will return the item to its place on the queue – for more info please refer to: http://blogs.msdn.com/drnick/ archive/2008/12/04/an-alternative-queuing-model.aspx) Dublin/Windows Application Server It is important to note that Microsoft are working on a new technology... http://blogs.msdn.com/adonet/archive/2008/10/31/clarifying-the-messageon-l2s-futures.aspx LINQ to SQL changes In VS2010/.NET 4.0 LINQ to SQL has a number of welcome performance enhancements and bug fixes It is slightly troublesome that there is very little information on this at the time of writing, but for a full list please see the blog post by Damien Guard (who works at Microsoft within the data programmability team) at http://damieng.com/blog/2009/06/01/linq-to-sql-changes-in-net-40... application for a hospital that stored data about patients in two tables: Person and Patient These tables had a one-to-one relationship Person held demographic details and Patient held clinical-specific information Whether this is the best database design is not important, but you can probably see that when you want to work with a “patient,” it is tedious to have to work with two separate objects EF allows... easier to adhere to naming conventions as classes and methods are automatically generated 176 CHAPTER 8 ENTITY FRAMEWORK It is worth noting that by utilizing an ORM framework for data access, you are introducing additional overhead to data access, and that for high performance applications, you may be better off working with the database directly Generally, however, the performance implications will . Different Types of Addresess Address Bindi ng http basicHttpBinding net. pipe netNamedPipeBinding net. msmq netMsmqBinding net. tcp netTcpBinding  TIP If you are using a configuration file or creating. Mcloughlin, a freelance .NET consultant specializing in WF and coordinator of the user group Nxtgen Southampton. John Mcloughlin http://blog.batfishsolutions.com/ With .NET 3. 0 Microsoft introduced. http://. However if the address specified began net. tcp://localhost:8081/greeting a netTcpBinding would be used. This is a huge step forward from WCF 3. 5 that made you create endpoints and would

Ngày đăng: 20/06/2014, 08:20

Từ khóa liên quan

Mục lục

  • Prelim

  • Contents at a Glance

  • Contents

  • About the Author

  • About the Technical Reviewer

  • Acknowledgments

    • Contributors

    • Introduction

      • …But We Will Give You All This!

      • Code Examples

      • Danger—Work in Progress!

      • Introduction

        • Versions

        • What Is .NET 4.0 and VS2010 All About?

          • Efficiency

          • Maturation of Existing Technologies

          • Extensibility

          • Influence of Current Trends

          • Multicore Shift

          • Unit Testing and Test-Driven Development

          • Cloud Computing

          • What Do Others Think About .NET 4.0?

            • Mike Ormond (Microsoft Evangelist)

            • Eric Nelson (Microsoft Evangelist)

            • Craig Murphy (MVP and developer community organizer)

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan