Share via


Walkthrough: Implementing a Transparent Process

This walkthrough creates a specific workflow operation to act as a base operation, and then creates a transparent process that runs when the base operation ends. The base operation models a simple product query service, which accepts a product name that a customer wishes to purchase. The service returns the cost of the product as a decimal value in the local currency. The transparent process then applies a discount to the price returned by the service.

The walkthrough implements the base workflow in a BLSpecific service project named ProductQueryBLSpecific in a DCS Solution project named ProductService. For detailed instructions about how to create the DCS Solution project, see Walkthrough: Creating a DCS Solution. The walkthrough creates the transparent process in another BLSpecific service project named ProductQueryTransparent. The walkthrough also creates messages in a messages project named ProductServiceMessages.

Before you begin

  1. Create a DCS solution in Visual Studio named ProductService in the E:\Walkthroughs folder. For detailed instructions about creating a DCS solution, see Walkthrough: Creating a DCS Solution.
  2. Create a messages project in the DCS Solution project named ProductServiceMessages. Create the project in the ProductServiceNamespace namespace and add default error and exception Message classes named ProductServiceError and ProductServiceException to the project. For detailed instructions about how to create a messages project, see Walkthrough: Creating a DCS Messages Project.

Detailed Instructions

To create Request and Response Message classes in the ProductServiceMessages project

  1. In Solution Explorer, right-click ProductServiceMessages, and then click Add Message Class.

  2. In the Add Message Class dialog box, in the Class box, type GetProductPriceRequest, and then click Finish.

  3. The following image shows the Add Message Class dialog box.

  4. Dd632260.b4a9d544-d004-4d7a-be3b-57eb552ea981(en-us,MSDN.10).png

  5. The Add Message Class dialog box, configured to create a new Message class named GetProductPriceRequest

  6. Repeat this procedure and add another Message class named GetProductPriceResponse.

After you create the default Message classes, you must customize them to contain the required data.

To customize the generated Message classes

  1. In Solution Explorer, under ProductServiceMessages, right-click GetProductPriceRequest.cs, and then click View Code.

  2. In the GetProductPriceRequest.cs file, expand the Private Fields region, and then add a line of code to create a private string field named _ProductName.

  3. Your code should resemble the following example.

  4. #region Private Fields
    private string _ProductName; 
    #endregion
    
  5. Expand the Public Properties region, and add code to create a public property to expose the _ProductName field. Name the property ProductName, and decorate it with the DataMember attribute. This enables the serialization runtime to serialize the Message class correctly.

  6. Your code should resemble the following example.

  7. #region Public Properties
    [DataMember]
    public string ProductName
    {
        get { return _ProductName; }
        set { _ProductName = value; }
    }
    #endregion
    
  8. On the File menu, click SaveGetProductPriceRequest.cs.

  9. On the File menu, click Close.

  10. In Solution Explorer, under ProductServiceMessages, right-click GetProductPriceResponse.cs, and then click View Code.

  11. In the GetProductPriceResponse.cs file, expand the Private Fields region, and then add a line of code to create a private double field.

  12. Your code should resemble the following example.

  13. #region Private Fields
    private double _ProductPrice;
    #endregion
    
  14. Expand the Public Properties region, and add code to create a public property to expose the private field. Name the property ProductPrice, and decorate it with the DataMember attribute.

  15. Your code should resemble the following example.

  16. #region Public Properties
    [DataMember]
    public double ProductPrice
    {
        get { return _ProductPrice; }
        set { _ProductPrice = value; }
    }
    #endregion
    
  17. On the File menu, click SaveGetProductPriceResponse.cs.

  18. On the File menu, click Close.

After you create the Message classes, you can create a BLSpecific project and implement the base operation.

Note

You implement a base service as you would any other workflow service. There are no specific requirements for the base service workflow implementation.

To create a BLSpecific project

  1. In Solution Explorer, right-click the BLSpecific folder, point to Add, and then click BL Specific.

  2. In the Add New Project dialog box, in the Templates list, click BL Specific.

  3. In the Name box, type ProductQueryBLSpecific, and then click Browse.

  4. In the Project Location dialog box, browse to the E:\Walkthroughs\ProductService\BLSpecific folder, and then click OK.

  5. In the Add New Project dialog box, click OK.

  6. The following image shows the Add New Project dialog box.

  7. Dd632260.dfed814a-682e-4d4a-983c-5557fb3bc113(en-us,MSDN.10).png

  8. The Add New Project dialog box, configured to create a new BL Specific project named ProductQueryBLSpecific in the E:\Walkthroughs\ProductService\BLSpecificfolder

  9. In the Create New BL Specific dialog box, in the Namespace box, type ProductServiceNamespace.

  10. In the Service Name box, type ProductServiceService, and then click Finish.

  11. The following image shows the Create New BL Specific Project dialog box.

  12. Dd632260.1e88f4dc-de91-4ef7-86e3-199be01e98fb(en-us,MSDN.10).png

  13. The Create New BL Specific Project dialog box, configured to create a new project in the ProductServiceNamespace namespace and create a service instance named ProductServiceService

  14. Visual Studio generates the project.

To create a specific workflow operation

  1. In Solution Explorer, right-click ProductQueryBLSpecific, and then click Add New Operation Request/Response.

  2. In the Add New Operation Request/Response dialog box on the OperationConfiguration page, in the OperationName field, type GetProductPrice, and then click Next.

  3. The following image shows the Operation Configuration page.

  4. Dd632260.88fb36da-743a-43d4-82d5-df97fcb94451(en-us,MSDN.10).png

  5. The Operation Configuration page of the Add New Operation Request/Response dialog box, configured to create a new operation named GetProductPrice

  6. On the Messages Selector page, click the ellipsis button (…) adjacent to the Select type of Request message box.

  7. In the Please choose a file dialog box, browse to the E:\Walkthroughs\ProductService\Messages\ProductServiceMessages\bin\Debug folder, click ProductServiceMessages.dll, and then click Open.

  8. In the Add New Operation Request/Response dialog box on the Messages Selector page, configure the operation messages as follows, and then click Next:

    • Select type of Request message: GetProductPriceRequest
    • Select type of Response message: GetProductPriceResponse
    • Select type of Error: ProductServiceError
    • Select type of Exception: ProductServiceException
  9. The following image shows the Messages Selector page.

  10. Dd632260.5b66436b-ad44-4bed-9d3a-99116eb7bdb1(en-us,MSDN.10).png

  11. The Messages Selector page of the Add New Operation Request/Response dialog box, configured to set the operation Request message to GetProductPriceRequest and the Response message to GetProductPriceResponse

  12. On the Messages Assemblies References page, in the Assemblies References list, verify that the ProductServiceMessages(Project) item is selected, and then click Finish.

  13. The following image shows the Messages Assemblies References page.

  14. Dd632260.b36a657e-d4a4-4452-8b74-986d65c044bd(en-us,MSDN.10).png

  15. The Messages Assemblies References page of the Add New Operation Request/Response dialog box

To implement workflow functionality in a specific workflow

  1. In Solution Explorer, under ProductQueryBLSpecific, in the GetProductPrice folder, right-click the GetProductPriceWorkflow.cs file, and then click View Designer.

  2. In the workflow designer, drag a Code activity from the toolbox onto the designer surface, and drop it at the top of the workflow sequence.

  3. Change the activity (Name) property to retrieveProductPrice, and then double-click the activity to create an event handler.

  4. Visual Studio opens the GetProductPriceWorkflow.cs code-behind file, and creates a new event handler method.

  5. Inside the retrieveProductPrice_ExecuteCode method, add code to set the ProductPrice property of the Response message to 24.99. This code simulates retrieving the product price from a data source such as another Web service or database.

  6. Your code should resemble the following example.

  7. private void retrieveProductPrice_ExecuteCode(object sender, EventArgs e)
    {
        this.Response.ProductPrice = 24.99;
    } 
    
  8. Switch back to the workflow designer

  9. From the toolbox, in the DCS group, drag a SendResponse activity onto the designer surface, and drop it below the retrieveProductPrice activity.

  10. Change the activity (Name) property to sendResponse.

  11. Bind the activity Response property to the workflow Response property:

    1. Click the Response property, and then click the ellipsis button (…) that appears.
    2. In the Bind 'Response' to an activity's property dialog box, on the Bind to an existing member tab, click Response, and then click OK.
  12. Your workflow should resemble the following image.

  13. Dd632260.2a3d7585-bbcd-430b-b3b1-2c3d322bccd6(en-us,MSDN.10).png

  14. A base sequential workflow implementation containing a single CodeActivity activity and a single SendResponseActivity activity

  15. On the Build menu, click Build ProductServiceBLSpecific.

You have now implemented the base service and operation. You can deploy the service and develop a client application. For more information about deploying DCS services, see Walkthrough: Deploying DCS Services by Using Visual Studio. For more information about building client applications, see Building Client Applications.

To create a transparent operation, you need a second BLSpecific project to contain the transparent process. You cannot create transparent processes in the same project as other workflow models. Create a second BLSpecific project using the procedure described earlier in this walkthrough. Name the project ProductServiceTransparent, specify the Namespace property as ProductServiceNamespace, and set the ServiceName property to ProductServiceTransparentService.

To create a transparent operation in a BLSpecific project

  1. In Solution Explorer, right-click ProductServiceTransparent, and then click Add New OperationRequest/Response.

  2. In the Add New Operation Request/Response project on the Operation Configuration page, in the Operation Name field, type ApplyDiscount, and then click Next.

  3. On the Messages Selector page, click the ellipsis button (…) adjacent to the Select type of Request message box.

  4. In the Please choose a file dialog box, browse to the C:\Program Files\Microsoft CIS\DCS\V1.0\Bin folder, click Microsoft.ConnectedIndustry.ProcessExecution.Common.dll, and then click Open.

  5. In the Select type of Request message field, click TransparentProcessRequestMessage.

  6. In the Select type of Response message field, click TransparentProcessResponseMessage.

  7. Click the ellipsis button (…) adjacent to the Select type of Error box, browse to the C:\Program Files\Microsoft CIS\DCS\V1.0\Bin folder, click Microsoft.ConnectedIndustry.ServiceModel.Common.dll, and then click OK.

  8. In the Select type of Error list, click FrameworkError.

  9. Click the ellipsis button (…) adjacent to the Selecttype of Exception box, browse to the C:\Program Files\Microsoft CIS\DCS\V1.0\Bin folder, click Microsoft.ConnectedIndustry.ServiceModel.Common.dll, and then click OK.

  10. In the Select type of Exception list, click FrameworkException, and then click Next.

  11. The following image shows the Messages Selector page.

  12. Dd632260.77fcae7b-2c6d-4ddd-bec7-80bc7fb4381d(en-us,MSDN.10).png

  13. The Messages Selector page of the Add New Operation Request/Response dialog box, configured to set the Request message of the transparent operation to TransparentProcessRequestMessage, and the Response message to TransparentProcessResponseMessage

  14. On the Messages Assemblies References page, verify that both the Microsoft.ConnectedIndustry.ProcessExecution.Common and the Microsoft.ConnectedInductry.ServiceModel.Common assemblies are selected, and then click Finish.

  15. The following image shows the Messages Assemblies References page.

  16. Dd632260.0f5a611d-7d58-434d-a2f5-132761c4715d(en-us,MSDN.10).png

  17. The Messages Assemblies References page of the Add New Operation Request/Response dialog box for a transparent service

To implement transparent workflow functionality in an operation

  1. In Solution Explorer, in the ProductServiceTransparent project, under ApplyDiscount, double-click ApplyDiscountWorkflow.cs to open the workflow in the workflow designer.

  2. From the toolbox, in the DCS section, drag a WaitForTransparentProcessEvent onto the designer surface and drop it at the top of the workflow sequence.

  3. Change the (Name) property to waitForGetProductPriceOperationComplete, and change the Event property to Ended. This specifies that the transparent process runs when the base operation is finished. For more information about the Event property, see How the DCS Runtime Injects a Transparent Process into a Service.

  4. Bind the InputData activity property to the workflow Request property

    1. Click the InputData property, and then double-click the Bind Property icon.
    2. In the Bind 'InputData' to an activity's property dialog box, click Request, and then click OK.
  5. From the Toolbox, drag a Code activity onto the workflow designer, and drop it below the waitForGetProductPriceOperationComplete activity.

  6. Change the (Name) property to applyDiscount, and then double-click the activity to create an event handler in the code-behind file.

  7. Visual Studio generates a method handler in the code-behind file, and opens the code file for editing.

  8. Note

    You access the base workflow response message by using the transparent workflow Response.OutputMessage property. You need to cast the property to the correct message type, and therefore require a reference to the messages project containing the Message classes used in the base workflow implementation.

  9. Add a reference to the messages project containing the base workflow messages.

    1. In Solution Explorer, in the ProductServiceTransparent project, right-click References, and then click Add Reference.
    2. In the Add Reference dialog box, on the Projects tab, click ProductServiceMessages, and then click OK.
  10. At the top of the ApplyDiscountWorkflow.cs file, expand the References section and add a line of code to bring the ProductServiceNamespace namespace into scope.

  11. Your code should resemble the following example.

  12. #region References
    ...
    using ProductServiceNamespace;
    #endregion
    
  13. In the applyDiscount_ExecuteCode method, add code to apply a 5% discount to the value of the Response.OutputMessage.ProductPrice property. Remember that you need to cast the OutputMessage property to the correct type.

  14. Your code should resemble the following example.

  15. private void applyDiscount_ExecuteCode(object sender, EventArgs e)
    {
        ((GetProductPriceResponse)Response.OutputMessage).ProductPrice *= 0.95;
    }
    
  16. Switch back to the workflow designer.

  17. From the toolbox, in the DCS section, drag a SendTransparentProcessResponse onto the designer surface and drop it at the top of the workflow sequence.

  18. Change the (Name) property to sendApplyDiscountResponse, and change the RelatedActivity property to waitForGetProductPriceOperationComplete.

  19. Your workflow should resemble the following image.

  20. Dd632260.b0f8d72b-7315-436d-b248-fed399c60e4e(en-us,MSDN.10).png

  21. A transparent operation implementation containing a WaitForTransparentEventAcvitivy activity, a CodeActivity activity, and a SendTransparentProcessResponseActivity activity

  22. Save the workflow implementation, build the project, and verify that there are no errors.

You have now implemented a base operation and a transparent process that DCS should invoke when the base operation executes. You can now deploy the service implementation and configure the transparent pipeline. For information about deploying a service, see Walkthrough: Deploying DCS Services by Using Visual Studio. For more information about configuring transparent pipelines, see Configuring a Transparent Process.

See Also

Walkthrough: Creating a DCS Solution

Walkthrough: Creating a DCS Messages Project

Walkthrough: Deploying DCS Services by Using Visual Studio

Building Client Applications

How the DCS Runtime Injects a Transparent Process into a Service

Configuring a Transparent Process