ISendMessageCallback.OnSendMessage(OperationContext) 方法

定义

发送服务消息时执行。

public:
 void OnSendMessage(System::ServiceModel::OperationContext ^ operationContext);
public void OnSendMessage (System.ServiceModel.OperationContext operationContext);
abstract member OnSendMessage : System.ServiceModel.OperationContext -> unit
Public Sub OnSendMessage (operationContext As OperationContext)

参数

operationContext
OperationContext

发送消息时所在的操作上下文。

示例

以下示例演示如何在消息在网络上发送之前将接口实现 ISendMessageCallback 到新标头的接口。

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

    public Guid InstanceId { get; set; }

    public void OnSendMessage(System.ServiceModel.OperationContext operationContext)
    {
        operationContext.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader(HeaderName, HeaderNS, this.InstanceId));
    }
}

适用于