Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / OperationContext.cs / 1 / OperationContext.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.ServiceModel
{
using System.Collections.Generic;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Channels;
using System.Runtime.Remoting.Contexts;
using System.IdentityModel.Claims;
using System.IdentityModel.Policy;
using System.ServiceModel.Security.Tokens;
using System.ServiceModel.Security;
using System.Security.Principal;
using System.Net.Security;
public sealed class OperationContext : IExtensibleObject
{
[ThreadStatic]
static OperationContext currentContext;
ServiceChannel channel;
Message clientReply;
bool closeClientReply;
ExtensionCollection extensions;
ServiceHostBase host;
RequestContext requestContext;
Message request;
InstanceContext instanceContext;
bool isServiceReentrant = false;
internal IPrincipal threadPrincipal;
TransactionRpcFacet txFacet;
MessageProperties outgoingMessageProperties;
MessageHeaders outgoingMessageHeaders;
MessageVersion outgoingMessageVersion;
EndpointDispatcher endpointDispatcher;
public event EventHandler OperationCompleted;
public OperationContext(IContextChannel channel)
{
if(channel == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("channel"));
ServiceChannel serviceChannel = channel as ServiceChannel;
//Could be a TransparentProxy
if (serviceChannel == null)
{
serviceChannel = ServiceChannelFactory.GetServiceChannel(channel);
}
if (serviceChannel != null)
{
this.outgoingMessageVersion = serviceChannel.MessageVersion;
this.channel = serviceChannel;
}
else
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxInvalidChannelToOperationContext)));
}
}
internal OperationContext(ServiceHostBase host)
: this(host, MessageVersion.Soap12WSAddressing10)
{
}
internal OperationContext(ServiceHostBase host, MessageVersion outgoingMessageVersion)
{
if (outgoingMessageVersion == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("outgoingMessageVersion"));
this.host = host;
this.outgoingMessageVersion = outgoingMessageVersion;
}
internal OperationContext(RequestContext requestContext, Message request, ServiceChannel channel, ServiceHostBase host)
{
this.channel = channel;
this.host = host;
this.requestContext = requestContext;
this.request = request;
this.outgoingMessageVersion = channel.MessageVersion;
}
public IContextChannel Channel
{
get { return this.GetCallbackChannel(); }
}
public static OperationContext Current
{
get { return currentContext; }
set { currentContext = value; }
}
public EndpointDispatcher EndpointDispatcher
{
get
{
return this.endpointDispatcher;
}
set
{
this.endpointDispatcher = value;
}
}
public bool IsUserContext
{
get
{
return (this.request == null);
}
}
public IExtensionCollection Extensions
{
get
{
if (this.extensions == null)
this.extensions = new ExtensionCollection(this);
return this.extensions;
}
}
internal bool IsServiceReentrant
{
get { return this.isServiceReentrant; }
set { this.isServiceReentrant = value; }
}
public bool HasSupportingTokens
{
get
{
MessageProperties properties = this.IncomingMessageProperties;
return properties != null && properties.Security != null &&
properties.Security.HasIncomingSupportingTokens;
}
}
public ServiceHostBase Host
{
get { return this.host; }
}
internal Message IncomingMessage
{
get { return this.clientReply ?? this.request; }
}
internal ServiceChannel InternalServiceChannel
{
get { return this.channel; }
set { this.channel = value; }
}
internal bool HasOutgoingMessageHeaders
{
get { return (this.outgoingMessageHeaders != null); }
}
public MessageHeaders OutgoingMessageHeaders
{
get
{
if (this.outgoingMessageHeaders == null)
this.outgoingMessageHeaders = new MessageHeaders(this.OutgoingMessageVersion);
return this.outgoingMessageHeaders;
}
}
internal bool HasOutgoingMessageProperties
{
get { return (this.outgoingMessageProperties != null); }
}
public MessageProperties OutgoingMessageProperties
{
get
{
if (this.outgoingMessageProperties == null)
this.outgoingMessageProperties = new MessageProperties();
return this.outgoingMessageProperties;
}
}
internal MessageVersion OutgoingMessageVersion
{
get { return this.outgoingMessageVersion; }
}
public MessageHeaders IncomingMessageHeaders
{
get
{
Message message = this.clientReply ?? this.request;
if (message != null)
return message.Headers;
else
return null;
}
}
public MessageProperties IncomingMessageProperties
{
get
{
Message message = this.clientReply ?? this.request;
if (message != null)
return message.Properties;
else
return null;
}
}
public MessageVersion IncomingMessageVersion
{
get
{
Message message = this.clientReply ?? this.request;
if (message != null)
return message.Version;
else
return null;
}
}
public InstanceContext InstanceContext
{
get { return this.instanceContext; }
}
public RequestContext RequestContext
{
get { return this.requestContext; }
set { this.requestContext = value; }
}
public ServiceSecurityContext ServiceSecurityContext
{
get
{
MessageProperties properties = this.IncomingMessageProperties;
if (properties != null && properties.Security != null)
{
return properties.Security.ServiceSecurityContext;
}
return null;
}
}
public string SessionId
{
get
{
if (this.channel != null)
{
IChannel inner = this.channel.InnerChannel;
if (inner != null)
{
ISessionChannel duplex = inner as ISessionChannel;
if ((duplex != null) && (duplex.Session != null))
return duplex.Session.Id;
ISessionChannel input = inner as ISessionChannel;
if ((input != null) && (input.Session != null))
return input.Session.Id;
ISessionChannel output = inner as ISessionChannel;
if ((output != null) && (output.Session != null))
return output.Session.Id;
}
}
return null;
}
}
public ICollection SupportingTokens
{
get
{
MessageProperties properties = this.IncomingMessageProperties;
if (properties != null && properties.Security != null)
{
return new System.Collections.ObjectModel.ReadOnlyCollection(
properties.Security.IncomingSupportingTokens);
}
return null;
}
}
internal IPrincipal ThreadPrincipal
{
get { return this.threadPrincipal; }
set { this.threadPrincipal = value; }
}
internal TransactionRpcFacet TransactionFacet
{
get { return this.txFacet; }
set { this.txFacet = value; }
}
internal void ClearClientReplyNoThrow()
{
this.clientReply = null;
}
internal void FireOperationCompleted()
{
try
{
EventHandler handler = this.OperationCompleted;
if (handler != null)
{
handler(this, EventArgs.Empty);
}
}
catch (Exception e)
{
if (DiagnosticUtility.IsFatal(e))
throw;
throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
}
}
public T GetCallbackChannel()
{
if (this.channel == null || this.IsUserContext)
return default(T);
// yes, we might throw InvalidCastException here. Is it really
// better to check and throw something else instead?
return (T)this.channel.Proxy;
}
internal void ReInit(RequestContext requestContext, Message request, ServiceChannel channel)
{
this.requestContext = requestContext;
this.request = request;
this.channel = channel;
}
internal void Recycle()
{
this.requestContext = null;
this.request = null;
this.extensions = null;
this.instanceContext = null;
this.threadPrincipal = null;
this.txFacet = null;
this.SetClientReply(null, false);
}
internal void SetClientReply(Message message, bool closeMessage)
{
Message oldClientReply = null;
if (!object.Equals(message, this.clientReply))
{
if (this.closeClientReply && (this.clientReply != null))
{
oldClientReply = this.clientReply;
}
this.clientReply = message;
}
this.closeClientReply = closeMessage;
if (oldClientReply != null)
{
oldClientReply.Close();
}
}
public void SetTransactionComplete()
{
if (this.txFacet == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.NoTransactionInContext)));
}
this.txFacet.Completed();
}
internal void SetInstanceContext(InstanceContext instanceContext)
{
this.instanceContext = instanceContext;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XmlIgnoreAttribute.cs
- XmlWrappingReader.cs
- odbcmetadatafactory.cs
- XPathScanner.cs
- ToolStripScrollButton.cs
- StandardBindingOptionalReliableSessionElement.cs
- Button.cs
- DataGridViewCellMouseEventArgs.cs
- BindUriHelper.cs
- AnonymousIdentificationModule.cs
- MailAddressParser.cs
- ControlIdConverter.cs
- DateTimeHelper.cs
- HttpListenerException.cs
- StringSorter.cs
- MultitargetingHelpers.cs
- DataTablePropertyDescriptor.cs
- BooleanSwitch.cs
- PasswordPropertyTextAttribute.cs
- BinaryNode.cs
- ItemContainerPattern.cs
- DataGridViewCellStyleBuilderDialog.cs
- ToolStripItemBehavior.cs
- TextRangeAdaptor.cs
- TextSelection.cs
- InputEventArgs.cs
- WebBrowserUriTypeConverter.cs
- LeftCellWrapper.cs
- Stack.cs
- MergeFilterQuery.cs
- _TLSstream.cs
- Pair.cs
- DataGridViewSelectedRowCollection.cs
- Stylesheet.cs
- FixedSOMPageConstructor.cs
- SecurityUtils.cs
- SimpleMailWebEventProvider.cs
- AlgoModule.cs
- AppDomainResourcePerfCounters.cs
- WebBrowserDocumentCompletedEventHandler.cs
- BinaryMethodMessage.cs
- ProcessHostMapPath.cs
- DirectoryNotFoundException.cs
- MultiplexingDispatchMessageFormatter.cs
- SqlSelectClauseBuilder.cs
- EncoderExceptionFallback.cs
- TcpChannelListener.cs
- MetadataPropertyAttribute.cs
- PermissionListSet.cs
- WebPartConnectionCollection.cs
- KeySpline.cs
- RefreshPropertiesAttribute.cs
- WaitForChangedResult.cs
- Filter.cs
- ValueType.cs
- MetadataLocation.cs
- DialogResultConverter.cs
- KeyValueInternalCollection.cs
- PolicyException.cs
- HashHelper.cs
- MergeFailedEvent.cs
- CompModSwitches.cs
- BindingValueChangedEventArgs.cs
- TTSVoice.cs
- PartBasedPackageProperties.cs
- GeneralTransform.cs
- ReadOnlyObservableCollection.cs
- ImageMap.cs
- ControlCollection.cs
- KeyFrames.cs
- VerbConverter.cs
- StringToken.cs
- ListSourceHelper.cs
- CodeArgumentReferenceExpression.cs
- FaultException.cs
- EmptyReadOnlyDictionaryInternal.cs
- TcpTransportSecurity.cs
- TreeIterator.cs
- Material.cs
- WinCategoryAttribute.cs
- NamespaceEmitter.cs
- CmsInterop.cs
- EncoderNLS.cs
- DataGridViewDataConnection.cs
- DCSafeHandle.cs
- CryptoHandle.cs
- _SecureChannel.cs
- MimeObjectFactory.cs
- DataGridViewCellMouseEventArgs.cs
- CursorConverter.cs
- DataGridViewLinkColumn.cs
- HttpCapabilitiesBase.cs
- OdbcCommandBuilder.cs
- XmlElementList.cs
- GridSplitter.cs
- SQLSingleStorage.cs
- MethodBuilderInstantiation.cs
- NativeObjectSecurity.cs
- SystemDropShadowChrome.cs
- FixedFlowMap.cs