IReceiveMessageCallback.OnReceiveMessage 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在接收到服務訊息時執行。
public:
void OnReceiveMessage(System::ServiceModel::OperationContext ^ operationContext, System::Activities::ExecutionProperties ^ activityExecutionProperties);
public void OnReceiveMessage (System.ServiceModel.OperationContext operationContext, System.Activities.ExecutionProperties activityExecutionProperties);
abstract member OnReceiveMessage : System.ServiceModel.OperationContext * System.Activities.ExecutionProperties -> unit
Public Sub OnReceiveMessage (operationContext As OperationContext, activityExecutionProperties As ExecutionProperties)
參數
- operationContext
- OperationContext
作業內容,訊息會在這個內容中接收。
- activityExecutionProperties
- ExecutionProperties
工作流程內可用的執行屬性集。
範例
下列範例將示範如何實作 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.");
}
}
}