IReceiveMessageCallback 接口

定义

实现 ReceiveReceiveParametersContent 活动收到服务消息时要执行的回调。

public interface class IReceiveMessageCallback
public interface IReceiveMessageCallback
type IReceiveMessageCallback = interface
Public Interface IReceiveMessageCallback

示例

下面的示例演示如何实现用于在收到消息时访问消息标头的 IReceiveMessageCallback 接口。

class ReceiveInstanceIdCallback : IReceiveMessageCallback
{
    public const string HeaderName = "InstanceIdHeader";
    public const string HeaderNS = "http://Microsoft.Samples.AccessingOperationContext";

    public void OnReceiveMessage(System.ServiceModel.OperationContext operationContext, System.Activities.ExecutionProperties activityExecutionProperties)
    {
        try
        {
            Guid instanceId = operationContext.IncomingMessageHeaders.GetHeader<Guid>(HeaderName, HeaderNS);
            Console.WriteLine("Received a message from a workflow with instanceId = {0}", instanceId);
        }
        catch (MessageHeaderException)
        {
            Console.WriteLine("This message must not be from a workflow.");
        }
    }
}

方法

OnReceiveMessage(OperationContext, ExecutionProperties)

收到服务消息时执行。

适用于