共用方式為


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)

在接收到服務訊息時執行。

適用於