Export (0) Print
Expand All

Receive Class

An activity that receives a message.

System::Object
  System.Activities::Activity
    System.ServiceModel.Activities::Receive

Namespace:  System.ServiceModel.Activities
Assembly:  System.ServiceModel.Activities (in System.ServiceModel.Activities.dll)

[ContentPropertyAttribute(L"Content")]
public ref class Receive sealed : public Activity

The Receive type exposes the following members.

  NameDescription
Public methodReceiveInitializes a new instance of the Receive class.
Top

  NameDescription
Public propertyActionGets or sets the value of the action header of the message.
Protected propertyCacheIdGets the identifier of the cache that is unique within the scope of the workflow definition. (Inherited from Activity.)
Public propertyCanCreateInstanceGets or sets a value that indicates whether a new workflow instance is created to process the message if the message does not correlate to an existing workflow instance..
Public propertyContentGets or sets the data to receive. The content can be either a ReceiveMessageContent or a ReceiveParametersContent.
Public propertyCorrelatesOnGets or sets the MessageQuerySet used to query the message to extract correlation data.
Public propertyCorrelatesWithGets or sets a correlation handle that is used to route the message to the appropriate workflow instance.
Public propertyCorrelationInitializersGets a collection of correlation initializers that initialize query-based, context, callback context, or request-reply correlations with a Send activity runs.
Public propertyDisplayNameGets or sets an optional friendly name that is used for debugging, validation, exception handling, and tracking. (Inherited from Activity.)
Public propertyIdGets an identifier that is unique in the scope of the workflow definition. (Inherited from Activity.)
Protected propertyImplementationVersionGets or sets the version of the implementation used. (Inherited from Activity.)
Public propertyKnownTypesGets a collection of known types for the operation.
Public propertyOperationNameGets or sets the name of the operation implemented by the Receive.
Public propertyProtectionLevelGets or sets a value that indicates the protection level for the operation.
Public propertySerializerOptionGets or sets a value that specifies the serializer to use for this operation.
Public propertyServiceContractNameGets or sets the name of the service contract.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodStatic memberFromOperationDescriptionReturns the receive activity from the given contract operation description.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodShouldSerializeCorrelatesOnReturns a value that indicates whether the CorrelatesOn property has changed from its default value and should be serialized.
Public methodShouldSerializeDisplayNameIndicates whether the DisplayName property should be serialized. (Inherited from Activity.)
Public methodToStringReturns a String that contains the Id and DisplayName of the Activity. (Inherited from Activity.)
Top

The Receive activity can receive a single item or multiple items depending on the type of receive content used.

Caution noteCaution

When a workflow contains multiple Receive activities with the same operation name, the CorrelatesOn property must be set to the same set of correlation queries.

The following example shows how to create a Receive activity and add it to a workflow in code.

Variable<string> message = new Variable<string> { Name = "message" };
Variable<string> echo = new Variable<string> { Name = "echo" };
Receive receiveString = new Receive
{
    OperationName = "Echo",
    ServiceContractName = "Echo",
    CanCreateInstance = true,
    //parameters for receive
    Content = new ReceiveParametersContent
    {
        Parameters = 
        {
            {"message", new OutArgument<string>(message)}
        }
    }
};

Sequence workflow = new Sequence()
{
    Variables = { message, echo },
    Activities =
        {
            receiveString,
            new WriteLine
            {
                Text = new InArgument<string>(env =>("Message received: " + message.Get(env)))
            },
            new Assign<string>
            {
                Value = new InArgument<string>(env =>("<echo> " + message.Get(env))),
                To = new OutArgument<string>(echo)
            },                        
            //parameters for reply 
            new SendReply
            {                           
                Request = receiveString,                            
                Content = new SendParametersContent
                {
                    Parameters =
                    {
                        { "echo", new InArgument<string>(echo) }
                    },
                }
            },
            new WriteLine
            {
                Text = new InArgument<string>(env =>("Message sent: " + echo.Get(env)))
            },
        },
};

service = new WorkflowService
{
    Name = "Echo",
    Body = workflow
};

The following example shows how to create a Receive activity and add it to a workflow service in XAML.

<WorkflowService mc:Ignorable="sap" ConfigurationName="Service1" Name="Service1" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/servicemodel" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="clr-namespace:Microsoft.VisualBasic;assembly=System" xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities" xmlns:p="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:s1="clr-namespace:System;assembly=System" xmlns:s2="clr-namespace:System;assembly=System.Xml" xmlns:s3="clr-namespace:System;assembly=System.Core" xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities" xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=System" xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System.ServiceModel" xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=System.Core" xmlns:scg3="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:sd="clr-namespace:System.Data;assembly=System.Data" xmlns:sl="clr-namespace:System.Linq;assembly=System.Core" xmlns:ssa="clr-namespace:System.ServiceModel.Activities;assembly=System.ServiceModel.Activities" xmlns:st="clr-namespace:System.Text;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <p:Sequence sad:XamlDebuggerXmlReader.FileName="c:\Projects\WFServiceSnippets\WFServiceSnippets\Service1.xamlx" sap:VirtualizedContainerService.HintSize="277,644" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces">
    <p:Sequence.Variables>
      <p:Variable x:TypeArguments="CorrelationHandle" Name="__handle1" />
      <p:Variable x:TypeArguments="x:String" Name="Message" />
      <p:Variable x:TypeArguments="x:String" Name="Echo" />
    </p:Sequence.Variables>
    <sap:WorkflowViewStateService.ViewState>
      <scg3:Dictionary x:TypeArguments="x:String, x:Object">
        <x:Boolean x:Key="IsExpanded">True</x:Boolean>
      </scg3:Dictionary>
    </sap:WorkflowViewStateService.ViewState>
    <Receive x:Name="__ReferenceID0" CanCreateInstance="True" DisplayName="ReceiveString" sap:VirtualizedContainerService.HintSize="255,90" OperationName="Echo" ServiceContractName="Echo">
      <Receive.CorrelationInitializers>
        <RequestReplyCorrelationInitializer CorrelationHandle="[__handle1]" />
      </Receive.CorrelationInitializers>
      <ReceiveParametersContent>
        <p:OutArgument x:TypeArguments="x:String" x:Key="message">[Message]</p:OutArgument>
      </ReceiveParametersContent>
    </Receive>
    <p:WriteLine sap:VirtualizedContainerService.HintSize="255,61" Text="[&quot;Message received: &quot; + Message]" />
    <p:Assign sap:VirtualizedContainerService.HintSize="255,58">
      <p:Assign.To>
        <p:OutArgument x:TypeArguments="x:String">[Echo]</p:OutArgument>
      </p:Assign.To>
      <p:Assign.Value>
        <p:InArgument x:TypeArguments="x:String">["&lt;echo&gt; " + Message]</p:InArgument>
      </p:Assign.Value>
    </p:Assign>
    <SendReply Request="{x:Reference __ReferenceID0}" DisplayName="SendReply" sap:VirtualizedContainerService.HintSize="255,90">
      <SendParametersContent>
        <p:InArgument x:TypeArguments="x:String" x:Key="echo">[Echo]</p:InArgument>
      </SendParametersContent>
    </SendReply>
    <p:WriteLine sap:VirtualizedContainerService.HintSize="255,61" Text="[&quot;Message sent: &quot; + Echo]" />
  </p:Sequence>
</WorkflowService>

.NET Framework

Supported in: 4.5, 4

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft