概念和管理

Posted by

本文转自:

本文转自:)

本文转自:

 

 

 

本主题专门介绍一项旧有技术。现在应通过使用以下链接来创建 XML Web 服务和
XML Web 服务客户端:    Windows Communication
Foundation   .   

WCF 数据服务 支持开放式数据协议 (OData) 将数据作为包含可通过 URI
进行寻址的资源的源进行公开。              这些资源按照Entity Data
Model)的实体关系惯例表示。
在此模型中,实体表示作为应用程序域中数据类型的数据操作单元,如客户、订单、项目和产品。
可以通过使用具象状态传输
(REST) 的语义(尤其是标准 HTTP 谓词 GET、PUT、POST 和
DELETE)访问和更改实体数据。

This topic applies to Windows Workflow Foundation 4 (WF4).

 

对资源进行寻址)              

Activities created using .NET Framework 3.0 or .NET Framework 3.5 can be
used in a .NET Framework 4 workflow by using the
Interop.aspx)
activity. This topic provides an overview of using the
Interop.aspx)
activity.

代码示例


    Visual Basic Note:   
The Interop activity does not appear in the workflow designer toolbox unless the workflow’s project has its Target Framework setting set to .Net Framework 4.

 

使用 ASP.NET 创建的 Web 服务可以定义和操作 SOAP 标头。通过在特定 SOAP
标头中定义表示数据的类并从
SoapHeader.aspx)
类派生它,便可完成 SOAP 标头的定义。

              

 

定义表示 SOAP 标头的类

  1. 创建一个从 SoapHeader 类派生的类,其名称与 SOAP
    标头的根元素匹配。

    C#

    复制window.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_1c7f2768-95a4-4f88-932f-e0bd605dda64’);)

    public class MyHeader : SoapHeader
    
 

VB

[复制](javascript:if%20(window.epx.codeSnippet)window.epx.codeSnippet.copyCode('CodeSnippetContainerCode_b783f9b9-716a-496f-9d8b-5e7292034c53');)

    Public Class MyHeader : Inherits SoapHeader
  1. 添加公共字段或属性,使其名称和每个元素的各个数据类型与 SOAP
    标头中的对应项匹配。

    例如,给定以下 SOAP 标头,后面的类定义一个表示该 SOAP 标头的类。

    C#

    复制window.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_ce85ac01-36e5-4ca1-b794-a94646bdd776’);)

    <soap:Header xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <MyHeader xmlns="http://www.contoso.com">
        <Created>dateTime</Expires>
        <Expires>long</Expires>
      </MyHeader>
    </soap:Header>
    
    public class MyHeader : SoapHeader 
    {
       public DateTime Created;
       public long Expires;
    }
    
 

VB

[复制](javascript:if%20(window.epx.codeSnippet)window.epx.codeSnippet.copyCode('CodeSnippetContainerCode_30a146ce-c140-4c94-bf40-2fb24939cc65');)

    Public Class MyHeader : Inherits SoapHeader 
       Public Created As DateTime
       Public Expires As Long
    End Class

            

Using the Interop Activity in .NET Framework 4 Workflows

In this topic, a .NET Framework 3.5 activity library is created that
contains a DiscountCalculator activity. The DiscountCalculator
calculates a discount based on a purchase amount and consists of a
SequenceActivity.aspx)
that contains a
PolicyActivity.aspx).

Note:
The .NET Framework 3.5 activity created in this topic uses a PolicyActivity to implement the logic of the activity. It is not required to use a custom .NET Framework 3.5 activity or the Interop activity in order to use rules in a .NET Framework 4 workflow. For an example of using rules in a .NET Framework 4 workflow without using the Interop activity, see the Policy Activity in .NET Framework 4 sample.

 

 

处理 Web 服务内的 SOAP 标头

  1. 向实现表示 SOAP 标头的类型的 Web 服务的类中添加一个公共成员。

    C#

    复制window.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_d1ec7485-8c76-43ea-a0f0-a84712bd1f4d’);)

    [WebService(Namespace="http://www.contoso.com")]
    public class MyWebService 
    {
        // Add a member variable of the type deriving from SoapHeader.
        public MyHeader timeStamp;
    

     

    VB

    复制window.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_891e17b3-a055-4fc1-97db-365d978dafed’);)

    <WebService(Namespace:="http://www.contoso.com")> _
    Public Class MyWebService
        ' Add a member variable of the type deriving from SoapHeader.
        Public TimeStamp As MyHeader
    
  2. 向旨在处理 SOAP 标头的每个 Web 服务方法应用一个
    SoapHeader.aspx)
    特性。将 SoapHeader 特性的 MemberName
    属性设置为在第一步中创建的成员变量的名称。

    C#

    复制window.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_5d7cb9f5-6957-4d67-8786-8a79ac846585’);)

        [WebMethod]
        [SoapHeader("timeStamp")]
        public void MyWebMethod()
    
 

VB

[复制](javascript:if%20(window.epx.codeSnippet)window.epx.codeSnippet.copyCode('CodeSnippetContainerCode_9cb96689-21dc-468b-9f46-f735a8b0ecac');)

        <WebMethod, SoapHeader("TimeStamp")> _ 
        Public Sub MyWebMethod()
  1. 在应用了 SoapHeader 特性的每个 Web
    服务方法内,访问在第一步中创建的成员变量,以处理在 SOAP
    标头中发送的数据。

    C#

    复制window.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_dafdcf70-8669-4357-9a53-b45aa410a1e3’);)

        [WebMethod]
        [SoapHeader("myHeaderMemberVariable")]
        public string MyWebMethod() 
        {
            // Verify that the client sent the SOAP Header.
            if (timeStamp == null) timeStamp = new MyHeader();
            // Set the value of the SoapHeader returned to the client.
            timeStamp.Expires = 60000;
            timeStamp.Created = DateTime.UtcNow;
    
            return("Hello World!");
        }
    
 

VB

[复制](javascript:if%20(window.epx.codeSnippet)window.epx.codeSnippet.copyCode('CodeSnippetContainerCode_4c2d4c44-4c05-4134-a3d3-a77438d11638');)

        <WebMethod,SoapHeader("TimeStamp", _
                              Direction:=SoapHeaderDirection.InOut)> _ 
        Public Function MyWebMethod() As String
            ' Process the SoapHeader.
            If (TimeStamp Is Nothing) Then
                TimeStamp = New MyHeader
            End If
            TimeStamp.Expires = 60000
            TimeStamp.Created = DateTime.UtcNow

            Return "Hello World!"
        End Function

在 OData 中,您可以通过使用
URI 对数据模型公开的任何数据进行寻址。               例如,下面的 URI
返回一个作为 Customers 实体集的源,该实体集中包含 Customer
实体类型的所有实例的项:

To create the .NET Framework 3.5 activity library project

  1. Open Visual Studio 2010 and select New and then Project…
    from the File menu.

  2. Expand the Other Project Types node in the Installed
    Templates
    pane and select Visual Studio Solutions.

  3. Select Blank Solution from the Visual Studio Solutions list.
    Type PolicyInteropDemo in the Name box and click OK.

  4. Right-click PolicyInteropDemo in Solution Explorer and
    select Add and then New Project….

    Tip:
    If the Solution Explorer window is not visible, select Solution Explorer from the View menu.

     

     

  5. In the Installed Templates list, select Visual C# and then
    Workflow. Select .NET Framework 3.5 from the .NET Framework
    version drop-down list, and then select Workflow Activity
    Library
    from the Templates list.

  6. Type PolicyActivityLibrary in the Name box and click OK.

  7. Right-click Activity1.cs in Solution Explorer and select
    Delete. Click OK to confirm.

示例

下面的代码示例演示如何在使用 ASP.NET 创建的 Web 服务中定义和处理 SOAP
标头。MyWebService Web 服务有一个名为 myHeaderMemberVariable
的成员变量,该变量属于从 SoapHeader (MyHeader) 派生的类型并设置为
SoapHeader 特性的 MemberName 属性。此外,还对指定
myHeaderMemberVariableMyWebMethod Web 服务方法应用了
SoapHeader 特性。在 MyWebMethod Web 服务方法内,访问
myHeaderMemberVariable 可获得 SOAP 标头的 Username XML 元素的值。

C#

VB.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-11)

复制window.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_d5bd048c-7c1d-40c8-a67c-dc062f02358d’);)

<%@ WebService Language="C#" Class="MyWebService" %>
using System.Web.Services;
using System.Web.Services.Protocols;

// Define a SOAP header by deriving from the SoapHeader class.
public class MyHeader : SoapHeader 
{
   public DateTime Created;
   public long Expires;
}

[WebService(Namespace="http://www.contoso.com")]
public class MyWebService 
{
    // Add a member variable of the type deriving from SoapHeader.
    public MyHeader myHeaderMemberVariable;

    // Apply a SoapHeader attribute.
    [WebMethod]
    [SoapHeader("myHeaderMemberVariable")]
    public void MyWebMethod() 
    {
        // Process the SoapHeader.
        if (myHeaderMemberVariable.Username == "admin")
        {
           // Do something interesting.
        }
    }
}

在上一示例中,如果对 MyWebMethod 的 SOAP 请求有一个 MyHeader SOAP
标头,并且有一个 UserName 元素设置为
Admin,则会执行附加代码。也就是说,下面的 SOAP 请求会导致该代码执行。

 

复制window.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_b38362ae-5d02-4c15-b1f7-5108e86ce104’);)

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <MyHeader xmlns="http://www.contoso.com">
      <Created>dateTime</Created>
      <Expires>long</Expires>
    </MyHeader>
  </soap:Header>
  <soap:Body>
    <MyWebMethod xmlns="http://www.contoso.com" />
  </soap:Body>
</soap:Envelope>

 

To create the DiscountCalculator activity

  1. Right-click PolicyActivityLibrary in Solution Explorer and
    select Add and then Activity….

  2. Select Activity (with code separation) from the Visual C#
    Items
    list. Type DiscountCalculator in the Name box and
    click OK.

  3. Right-click DiscountCalculator.xoml in Solution Explorer and
    select View Code.

  4. Add the following three properties to the DiscountCalculator
    class.

    C#

    Copywindow.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_cbaad407-95d2-4048-8862-53e12651c05d’);)

    public partial class DiscountCalculator : SequenceActivity
    {
        public double Subtotal { get; set; }
        public double DiscountPercent { get; set; }
        public double Total { get; set; }
    }
    
  5. Right-click DiscountCalculator.xoml in Solution Explorer and
    select View Designer.

  6. Drag a Policy activity from the Windows Workflow v3.0
    section of the Toolbox and drop it in the DiscountCalculator
    activity.

    Tip:
    If the Toolbox window is not visible, select Toolbox from the View menu.

     

     

另请参见

复制window.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_148a37c2-3c63-46ae-abba-c400282582ee’);)

To configure the rules

  1. Click the newly added Policy activity to select it, if it is not
    already selected.

  2. Click the RuleSetReference property in the Properties window
    to select it, and click the ellipsis button to the right of the
    property.

    Tip:
    If the Properties window is not visible, choose Properties Window from the View menu.

     

     

  3. Select Click New….

  4. Click Add Rule.

  5. Type the following expression into the Condition box.

     

    Copywindow.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_39b56978-e3d2-421f-b30e-43e4642e4551’);)

    this.Subtotal >= 50 && this.Subtotal < 100
    
  6. Type the following expression into the Then Actions box.

     

    Copywindow.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_4f9f6df8-195d-42a8-ad47-426d48504476’);)

    this.DiscountPercent = 0.075
    
  7. Click Add Rule.

  8. Type the following expression into the Condition box.

     

    Copywindow.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_c46564c8-a894-437e-a4a0-d467e5f69e4e’);)

    this.Subtotal >= 100
    
  9. Type the following expression into the Then Actions box.

     

    Copywindow.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_885e97a6-5121-4de1-a29d-409a0634f532’);)

    this.DiscountPercent = 0.15
    
  10. Click Add Rule.

  11. Type the following expression into the Condition box.

     

    Copywindow.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_2320505b-f474-4dc2-a0c9-4cbb21b28057’);)

    this.DiscountPercent > 0
    
  12. Type the following expression into the Then Actions box.

     

    Copywindow.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_6550e21e-15a0-4fc1-9b40-13998b181d12’);)

    this.Total = this.Subtotal - this.Subtotal * this.DiscountPercent
    
  13. Type the following expression into the Else Actions box.

     

    Copywindow.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_5a470e66-1dc8-4b9c-b4be-c87c7f7fdaa2’);)

    this.Total = this.Subtotal
    
  14. Click OK to close the Rule Set Editor dialog box.

  15. Ensure that the newly-created
    RuleSet.aspx)
    is selected in the Name list, and click OK.

  16. Press CTRL+SHIFT+B to build the solution.

The rules added to the DiscountCalculator activity in this procedure
are shown in the following code example.

 

Copywindow.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_a8ab134f-c09d-40e7-a49f-255d57445d3e’);)

Rule1: IF this.Subtotal >= 50 && this.Subtotal < 100 
       THEN this.DiscountPercent = 0.075 

Rule2: IF this. Subtotal >= 100 
       THEN this.DiscountPercent = 0.15 

Rule3: IF this.DiscountPercent > 0 
       THEN this.Total = this.Subtotal - this.Subtotal * this.DiscountPercent 
       ELSE this.Total = this.Subtotal

When the
PolicyActivity.aspx)
executes, these three rules evaluate and modify the Subtotal,
DiscountPercent, and Total property values of the
DiscountCalculator activity to calculate the desired discount.

参考

SoapHeader.aspx)
SoapHeaderAttribute.aspx)
SoapUnknownHeader.aspx)
SoapHeaderException.aspx)

http://services.odata.org/Northwind/Northwind.svc/Customers

Using the DiscountCalculator Activity with the Interop Activity

To use the DiscountCalculator activity inside a .NET Framework 4
workflow, the
Interop.aspx)
activity is used. In this section two workflows are created, one using
code and one using the workflow designer, which show how to use the
Interop.aspx)
activity with the DiscountCalculator activity. The same host
application is used for both workflows.

概念

生成 XML Web services
客户端.aspx)

实体具有称为实体键的特殊属性。
实体键用于在实体集中唯一标识某个实体。
这样,您可以在实体集中对某种实体类型的特定实例进行寻址。
例如,下面的 URI 返回
Customer 实体类型的具有键值 ALFKI
的特定实例的项:

To create the host application

  1. Right-click PolicyInteropDemo in Solution Explorer and
    select Add, and then New Project….

  2. Ensure that .NET Framework 4 is selected in the .NET Framework
    version drop-down list, and select Workflow Console Application
    from the Visual C# Items list.

  3. Type PolicyInteropHost into the Name box and click OK.

  4. Right-click PolicyInteropHost in Solution Explorer and
    select Properties.

  5. In the Target framework drop-down list, change the selection
    from .NET Framework 4 Client Profile to .NET Framework 4.
    Click Yes to confirm.

  6. Right-click PolicyInteropHost in Solution Explorer and
    select Add Reference….

  7. Select PolicyActivityLibrary from the Projects tab and click
    OK.

  8. Right-click PolicyInteropHost in Solution Explorer and
    select Add Reference….

  9. Select System.Workflow.Activities,
    System.Workflow.ComponentModel, and then
    System.Workflow.Runtime from the .NET tab and click OK.

  10. Right-click PolicyInteropHost in Solution Explorer and
    select Set as StartUp Project.

  11. Press CTRL+SHIFT+B to build the solution.

其他资源

使用 SOAP
标头.aspx)
使用 ASP.NET 的 XML Web
services.aspx)

 

 

Using the Interop Activity in Code

In this example, a workflow definition is created using code that
contains the
Interop.aspx)
activity and the DiscountCalculator activity. This workflow is invoked
using
WorkflowInvoker.aspx)
and the results of the rule evaluation are written to the console using
a
WriteLine.aspx)
activity.

复制window.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_6333d545-9a2a-4b2f-98ad-c11e69365759’);)

To use the Interop activity in code

  1. Right-click Program.cs in Solution Explorer and select
    View Code.

  2. Add the following using statement at the top of the file.

    C#

    Copywindow.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_638e9019-32fd-4bf2-88de-d9ac4eac428a’);)

    using PolicyActivityLibrary;
    
  3. Remove the contents of the Main method and replace with the
    following code.

    C#

    Copywindow.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_89a3a203-4765-433b-bb28-70932a2a8604’);)

    static void Main(string[] args)
    {
        CalculateDiscountUsingCodeWorkflow();
    }
    
  4. Create a new method in the Program class called
    CalculateDiscountUsingCodeWorkflow that contains the following
    code.

    C#

    Copywindow.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_ff6ccd69-9a75-4dbd-86b5-71c98ff3ca80’);)

    static void CalculateDiscountUsingCodeWorkflow()
    {
        Variable<double> Subtotal = new Variable<double>
        {
            Default = 75.99,
            Name = "Subtotal"
        };
    
        Variable<double> DiscountPercent = new Variable<double>
        {
            Name = "DiscountPercent"
        };
    
        Variable<double> Total = new Variable<double>
        {
            Name = "Total"
        };
    
        Activity wf = new Sequence
        {
            Variables = { Subtotal, DiscountPercent, Total },
            Activities = 
            {
                new Interop
                {
                    ActivityType = typeof(DiscountCalculator),
                    ActivityProperties = 
                    {
                        { "Subtotal", new InArgument<double>(Subtotal) },
                        { "DiscountPercentOut", new OutArgument<double>(DiscountPercent) },
                        { "TotalOut", new OutArgument<double>(Total) }
                    }
                },
                new WriteLine
                {
                    Text =  new InArgument<string>(env => 
                        string.Format("Subtotal: {0:C}, Discount {1}%, Total {2:C}", 
                        Subtotal.Get(env), DiscountPercent.Get(env) * 100, Total.Get(env)))
                }
            }
        };
    
        WorkflowInvoker.Invoke(wf);
    }
    
    Note:
    The Subtotal, DiscountPercent, and Total properties of the DiscountCalculator activity are surfaced as arguments of the Interop activity, and bound to local workflow variables in the Interop activity’s ActivityProperties collection. Subtotal is added as an In argument because the Subtotal data flows into the Interop activity, and DiscountPercent and Total are added as Out arguments because their data flows out of the Interop activity. Note that the two Out arguments are added with the names DiscountPercentOut and TotalOut to indicate that they represent Out arguments. The DiscountCalculator type is specified as the Interop activity’s ActivityType.

     

     

  5. Press CTRL+F5 to build and run the application. Substitute different
    values for the Subtotal value to test out the different discount
    levels provided by the DiscountCalculator activity.

    C#

    Copywindow.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_17048487-4e84-475b-90a6-da1a5cbae842’);)

    Variable<double> Subtotal = new Variable<double>
    {
        Default = 75.99, // Change this value.
        Name = "Subtotal"
    };
    
http://services.odata.org/Northwind/Northwind.svc/Customers('ALFKI')

Using the Interop Activity in the Workflow Designer

In this example, a workflow is created using the workflow designer. This
workflow has the same functionality as the previous example, except than
instead of using a
WriteLine.aspx)
activity to display the discount, the host application retrieves and
displays the discount information when the workflow completes. Also,
instead of using local workflow variables to contain the data, arguments
are created in the workflow designer and the values are passed in from
the host when the workflow is invoked.

也可以对实体实例的基元属性和复杂属性进行单独寻址。
例如,下面的 URI
返回一个包含特定客户的 ContactName 属性值的 XML
元素:

To host the PolicyActivity using a Workflow Designer-created workflow

  1. Right-click Workflow1.xaml in Solution Explorer and select
    Delete. Click OK to confirm.

  2. Right-click PolicyInteropHost in Solution Explorer and
    select Add, New Item….

  3. Expand the Visual C# Items node and select Workflow. Select
    Activity from the Visual C# Items list.

  4. Type DiscountWorkflow into the Name box and click Add.

  5. Click the Arguments button on the lower left side of the
    workflow designer to display the Arguments pane.

  6. Click Create Argument.

  7. Type Subtotal into the Name box, select In from the
    Direction drop-down, select Double from the Argument
    type
    drop-down, and then press ENTER to save the argument.

    Note:
    If Double is not in the Argument type drop-down list, select Browse for Types …, type System.Double in the Type Name box, and click OK.

     

     

  8. Click Create Argument.

  9. Type DiscountPercent into the Name box, select Out from
    the Direction drop-down, select Double from the Argument
    type
    drop-down, and then press ENTER to save the argument.

  10. Click Create Argument.

  11. Type Total into the Name box, select Out from the
    Direction drop-down, select Double from the Argument
    type
    drop-down, and then press ENTER to save the argument.

  12. Click the Arguments button on the lower left side of the
    workflow designer to close the Arguments pane.

  13. Drag a Sequence activity from the Control Flow section of
    the Toolbox and drop it onto the workflow designer surface.

  14. Drag an Interop activity from the Migration section of the
    Toolbox and drop it in the Sequence activity.

  15. Click the Interop activity on the Click to browse… label,
    type DiscountCalculator in the Type Name box, and click
    OK.

    Note:
    When the Interop activity is added to the workflow and the DiscountCalculator type is specified as its ActivityType, the Interop activity exposes three In arguments and three Out arguments that represent the three public properties of the DiscountCalculator activity. The In arguments have the same name as the three public properties, and the three Out arguments have the same names with Out appended to the property name. In the following steps, the workflow arguments created in the previous steps are bound to the Interop activity’s arguments.

     

     

  16. Type DiscountPercent into the Enter a VB expression box to
    the right of the DiscountPercentOut property and press TAB.

  17. Type Subtotal into the Enter a VB expression box to the
    right of the Subtotal property and press TAB.

  18. Type Total into the Enter a VB expression box to the right
    of the TotalOut property and press TAB.

  19. Right-click Program.cs in Solution Explorer and select
    View Code.

  20. Add the following using statement at the top of the file.

    C#

    Copywindow.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_687fb955-d16c-46e2-ad69-60a375aafeaf’);)

    using System.Collections.Generic;
    
  21. Comment out the call to the CalculateDiscountInCode method in the
    Main method and add the following code.

    Note:
    If you did not follow the previous procedure and the default Main code is present, replace the contents of Main with the following code.

     

     

    C#

    Copywindow.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_209002d2-1988-44a5-98d3-0218255204a1’);)

    static void Main(string[] args)
    {
        CalculateDiscountUsingDesignerWorkflow();
        //CalculateDiscountUsingCodeWorkflow();
    }
    
  22. Create a new method in the Program class called
    CalculateDiscountUsingDesignerWorkflow that contains the following
    code.

    C#

    Copywindow.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_be4ba5cd-677b-48fb-bbaa-7b378f0cecff’);)

    static void CalculateDiscountUsingDesignerWorkflow()
    {
        double SubtotalValue = 125.99;
        Dictionary<string, object> wfargs = new Dictionary<string, object>
        {
            {"Subtotal", SubtotalValue}
        };
    
        Activity wf = new DiscountWorkflow();
    
        IDictionary<string, object> outputs =
            WorkflowInvoker.Invoke(wf, wfargs);
    
        Console.WriteLine("Subtotal: {0:C}, Discount {1}%, Total {2:C}",
            SubtotalValue, (double)outputs["DiscountPercent"] * 100,
            outputs["Total"]);
    }
    
  23. Press CTRL+F5 to build and run the application. To specify a
    different Subtotal amount, change the value of SubtotalValue in
    the following code.

    C#

    Copywindow.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_6c326951-9d43-40a5-b3b9-18e82fd4a275’);)

    double SubtotalValue = 125.99; // Change this value.
    

 

Rules Features Overview

The WF rules engine provides support for processing rules in a
priority-based manner with support for forward chaining. Rules can be
evaluated for a single item or for items in a collection. For an
overview of rules and information on specific rules functionality,
please refer to the following table.

复制window.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_ed78fe6a-4ea3-4331-9a11-d364a3e5feec’);)

 

Rules Feature Documentation

Rules Overview

Introduction to the Windows Workflow Foundation Rules Engine

RuleSet

Using RuleSets in Workflows and RuleSet

Evaluation of Rules

Rules Evaluation in RuleSets

Rules Chaining

Forward Chaining Control and Forward Chaining of Rules

Processing Collections in Rules

Processing Collections in Rules

Using the PolicyActivity

Using the PolicyActivity Activity and PolicyActivity

Workflows created in .NET Framework 4 do not use all of the rules
features provided by WF, such as declarative activity conditions and
conditional activities such as the
ConditionedActivityGroup.aspx)
and
ReplicatorActivity.aspx).
If required, this functionality is available for workflows created using
.NET Framework 3.0 and .NET Framework 3.5. For more information,
seeMigrating
Workflows.aspx).

http://services.odata.org/Northwind/Northwind.svc/Customers('ALFKI')/ContactName

如果在上面的 URI 中包括
$value
终结点,则只在响应消息中返回基元属性的值。 下面的示例只返回字符串“Maria
Anders”,而不返回 XML 元素:

 

复制window.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_e0788e7c-937b-455f-a9a2-702bce21213e’);)

http://services.odata.org/Northwind/Northwind.svc/Customers('ALFKI')/ContactName/$value

实体之间的关系在数据模型中由关联定义。
通过这些关联,可以使用实体实例的导航属性对相关实体进行寻址。
对于多对一的关系,导航属性可返回单个相关实体;对于一对多的关系,导航属性可返回一组相关实体。
例如,下面的 URI
返回一个作为与特定客户相关的所有订单集的源:

 

复制window.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_bb0a63e1-8d2e-4a60-9aed-842c634d23de’);)

http://services.odata.org/Northwind/Northwind.svc/Customers('ALFKI')/Orders

通常为双向的关系由一对导航属性表示。
作为对前一示例中所示的关系的反转,下面的
URI 返回对特定 Order 实体所属的 Customer 实体的引用:

 

复制window.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_55929883-337f-4e52-bacb-476f555a8e88’);)

http://services.odata.org/Northwind/Northwind.svc/Orders(10643)/Customer

通过
OData,还可以基于查询表达式的结果进行资源寻址。 这样,可以基于计算的表达式对资源集进行筛选。
例如,下面的 URI
对资源进行筛选以仅返回指定客户自 1997 年 9 月 22 日起已发货的订单:

 

复制window.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_d5ca46f0-8e0d-4caf-8219-5ccfd43946a1’);)

http://services.odata.org/Northwind/Northwind.svc/Customers('ALFKI')/Orders?$filter=ShippedDate gt datetime'1997-09-22T00:00:00'

有关更多信息,请参见
OData:URI
约定(可能为英文网页)。

系统查询选项)              


              

            

OData
定义了一组系统查询选项,您可以使用这些选项对资源执行传统的查询操作,如筛选、排序和分页。              
例如,下面的 URI
返回邮政编码尾号不是 100 的所有 Order 实体集和相关的 Order_Detail
实体:

 

复制window.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_7c603e8d-ce0a-4b5b-b6eb-694fa4077a29’);)

http://services.odata.org/Northwind/Northwind.svc/Orders?$filter=not endswith(ShipPostalCode,'100')&$expand=Order_Details&$orderby=ShipCity

返回源中的各项还按订单的
ShipCity 属性值进行排序。

WCF 数据服务支持下列 OData
系统查询选项:

 

查询选项

说明

$orderby

定义用于返回的源中的实体的默认排序顺序。 下面的查询按市/县对返回的客户源进行排序:

http://services.odata.org/Northwind/Northwind.svc/Customers?$orderby=Country,City

有关更多信息,请参见 OData: OrderBy 系统查询选项 ($orderby)(可能为英文网页)。

$top

指定要包括在返回的源中的实体数。 下面的示例跳过前 10 个客户,然后返回接下来的 10 个客户:

http://services.odata.org/Northwind/Northwind.svc/Customers?$skip=10&$top=10

有关更多信息,请参见 OData:Top 系统查询选项 ($top)(可能为英文网页)。

$skip

指定开始在源中返回实体前要跳过的实体数。 下面的示例跳过前 10 个客户,然后返回接下来的 10 个客户:

http://services.odata.org/Northwind/Northwind.svc/Customers?$skip=10&$top=10

有关更多信息,请参见 OData:Skip 系统查询选项 ($skip)(可能为英文网页)。

$filter

定义一个基于特定条件对源中返回的实体进行筛选的表达式。 此查询选项支持一组用于计算筛选表达式的逻辑比较运算符、算术运算符和预定义查询函数。 下面示例返回邮政编码尾号不是 100 的所有订单:

http://services.odata.org/Northwind/Northwind.svc/Orders?$filter=not endswith(ShipPostalCode,’100′)

有关更多信息,请参见 OData:Filter 系统查询选项 ($filter)(可能为英文网页)。

$expand

指定由查询返回哪些相关实体。 相关实体将作为源或内联项与查询返回的实体包含在一起。 下面的示例返回客户“ALFKI”的订单以及每个订单的项目详细信息:

http://services.odata.org/Northwind/Northwind.svc/Customers(‘ALFKI’)/Orders?$expand=Order_Details

有关更多信息,请参见 OData:Expand 系统查询选项 ($expand)(可能为英文网页)。

$select

指定一个投影,用于定义在投影中返回的实体的属性。 默认情况下,在源中返回实体的所有属性。 下面的查询仅返回 Customer 实体的三个属性:

http://services.odata.org/Northwind/Northwind.svc/Customers?$select=CustomerID,CompanyName,City

有关更多信息,请参见 OData:Select 系统查询选项 ($select)(可能为英文网页)。

$inlinecount

请求在源中包括源中返回的实体数的计数。 有关更多信息,请参见 OData: Inlinecount 系统查询选项 ($inlinecount)(可能为英文网页)。

对关系进行寻址)              


              

            

除了对实体集和实体实例进行寻址之外,通过
OData 还可对表示实体间关系的关联进行寻址。               若要创建或更改两个实体实例(例如与
Northwind 示例数据库中指定订单相关的发货方)之间的关系,必须使用此功能。
OData 支持 $link 运算符,专用于对实体间的关联进行寻址。 例如,在 HTTP PUT
请求消息中指定下面的 URI 可将指定订单的发货方更改为新发货方。

 

复制window.epx.codeSnippet.copyCode(‘CodeSnippetContainerCode_d02f8926-b475-46f0-905a-7cb59c760cf0’);)

http://services.odata.org/Northwind/Northwind.svc/Orders(10643)/$links/Shipper

有关更多信息,请参见
OData:对各项之间的链接进行寻址(可能为英文网页)。

使用返回的源)              


              

            

使用 OData 资源的 URI
可以对该服务公开的实体数据进行寻址。               在 Web
浏览器的地址字段中输入 URI 时,将以 OData 源表示形式返回请求的资源。
有关更多信息,请参见 WCF
数据服务快速入门)。
尽管可以使用 Web
浏览器测试某个数据服务资源能否返回预期的数据,但是生产数据服务(这些服务也可创建、更新和删除数据)通常由应用程序代码或网页中的脚本编写语言访问。
有关更多信息,请参见在客户端应用程序中使用
OData 服务 (WCF Data
Services))。

 

相关文章

Leave a Reply

电子邮件地址不会被公开。 必填项已用*标注