共用方式為


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));
    }
}

適用於