OperationContext.OutgoingMessageHeaders Property
.NET Framework 4
Gets the outgoing message headers for the active OperationContext.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
Property Value
Type: System.ServiceModel.Channels.MessageHeadersA MessageHeaders object that contains outbound message headers for the active OperationContext.
The following example shows how to use the OperationContextScope to create a new context in a client application in order to add a custom header to the outgoing message.
SampleServiceClient wcfClient = new SampleServiceClient(new InstanceContext(this)); try { using (OperationContextScope scope = new OperationContextScope(wcfClient.InnerChannel)) { MessageHeader header = MessageHeader.CreateHeader( "Service-Bound-CustomHeader", "http://Microsoft.WCF.Documentation", "Custom Happy Value." ); OperationContext.Current.OutgoingMessageHeaders.Add(header); // Making calls. Console.WriteLine("Enter the greeting to send: "); string greeting = Console.ReadLine(); //Console.ReadLine(); header = MessageHeader.CreateHeader( "Service-Bound-OneWayHeader", "http://Microsoft.WCF.Documentation", "Different Happy Value." ); OperationContext.Current.OutgoingMessageHeaders.Add(header); // One-way wcfClient.Push(greeting); this.wait.WaitOne(); // Done with service. wcfClient.Close(); Console.WriteLine("Done!"); Console.ReadLine(); } } catch (TimeoutException timeProblem) { Console.WriteLine("The service operation timed out. " + timeProblem.Message); Console.ReadLine(); wcfClient.Abort(); } catch (CommunicationException commProblem) { Console.WriteLine("There was a communication problem. " + commProblem.Message); Console.ReadLine(); wcfClient.Abort(); }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.