Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Security / ApplySecurityAndSendAsyncResult.cs / 1 / ApplySecurityAndSendAsyncResult.cs
//----------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel.Security
{
using System.Runtime.InteropServices;
using System.ServiceModel.Channels;
abstract class ApplySecurityAndSendAsyncResult : AsyncResult
where MessageSenderType : class
{
readonly MessageSenderType channel;
readonly SecurityProtocol binding;
volatile bool secureOutgoingMessageDone;
static AsyncCallback sharedCallback = DiagnosticUtility.ThunkAsyncCallback(new AsyncCallback(SharedCallback));
SecurityProtocolCorrelationState newCorrelationState;
TimeoutHelper timeoutHelper;
public ApplySecurityAndSendAsyncResult(SecurityProtocol binding, MessageSenderType channel, TimeSpan timeout,
AsyncCallback callback, object state)
: base(callback, state)
{
this.binding = binding;
this.channel = channel;
this.timeoutHelper = new TimeoutHelper(timeout);
}
protected SecurityProtocolCorrelationState CorrelationState
{
get { return newCorrelationState; }
}
protected SecurityProtocol SecurityProtocol
{
get { return this.binding; }
}
protected void Begin(Message message, SecurityProtocolCorrelationState correlationState)
{
IAsyncResult result = this.binding.BeginSecureOutgoingMessage(message, timeoutHelper.RemainingTime(), correlationState, sharedCallback, this);
if (result.CompletedSynchronously)
{
this.binding.EndSecureOutgoingMessage(result, out message, out newCorrelationState);
bool completedSynchronously = this.OnSecureOutgoingMessageComplete(message);
if (completedSynchronously)
{
Complete(true);
}
}
}
protected static void OnEnd(ApplySecurityAndSendAsyncResult self)
{
AsyncResult.End>(self);
}
bool OnSecureOutgoingMessageComplete(Message message)
{
if (message == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("message"));
}
this.secureOutgoingMessageDone = true;
IAsyncResult result = BeginSendCore(this.channel, message, timeoutHelper.RemainingTime(), sharedCallback, this);
if (!result.CompletedSynchronously)
{
return false;
}
EndSendCore(this.channel, result);
return this.OnSendComplete();
}
protected abstract IAsyncResult BeginSendCore(MessageSenderType channel, Message message, TimeSpan timeout, AsyncCallback callback, object state);
protected abstract void EndSendCore(MessageSenderType channel, IAsyncResult result);
bool OnSendComplete()
{
OnSendCompleteCore(timeoutHelper.RemainingTime());
return true;
}
protected abstract void OnSendCompleteCore(TimeSpan timeout);
static void SharedCallback(IAsyncResult result)
{
if (result == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("result"));
}
if (result.CompletedSynchronously)
{
return;
}
ApplySecurityAndSendAsyncResult self = result.AsyncState as ApplySecurityAndSendAsyncResult;
if (self == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.InvalidAsyncResult), "result"));
}
bool completeSelf = false;
Exception completionException = null;
try
{
if (!self.secureOutgoingMessageDone)
{
Message message;
self.binding.EndSecureOutgoingMessage(result, out message, out self.newCorrelationState);
completeSelf = self.OnSecureOutgoingMessageComplete(message);
}
else
{
self.EndSendCore(self.channel, result);
completeSelf = self.OnSendComplete();
}
}
#pragma warning suppress 56500 // covered by FxCOP
catch (Exception e)
{
if (Diagnostics.ExceptionUtility.IsFatal(e))
throw;
completeSelf = true;
completionException = e;
}
if (completeSelf)
{
self.Complete(false, completionException);
}
}
}
}
// 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
- MetafileHeaderWmf.cs
- DataKey.cs
- Helpers.cs
- ToolStripButton.cs
- HwndSubclass.cs
- BatchServiceHost.cs
- MethodRental.cs
- DTCTransactionManager.cs
- EncoderExceptionFallback.cs
- Enumerable.cs
- VectorValueSerializer.cs
- EntityDesignerUtils.cs
- BrowserInteropHelper.cs
- TypeSource.cs
- CheckBoxList.cs
- ExpressionBuilderContext.cs
- SqlNotificationEventArgs.cs
- NamespaceDecl.cs
- HijriCalendar.cs
- InputProcessorProfiles.cs
- Vector3DIndependentAnimationStorage.cs
- XmlCharType.cs
- ContextMarshalException.cs
- NativeObjectSecurity.cs
- BasePattern.cs
- XPathExpr.cs
- AssemblyFilter.cs
- ClientRoleProvider.cs
- FeatureSupport.cs
- CrossSiteScriptingValidation.cs
- Utils.cs
- BinaryEditor.cs
- RadioButton.cs
- EditorPartDesigner.cs
- XsltConvert.cs
- StatusBarPanelClickEvent.cs
- TextRangeEditTables.cs
- WindowsIdentity.cs
- Function.cs
- OletxTransactionManager.cs
- PropertyCollection.cs
- ToolStripDropDownButton.cs
- HwndPanningFeedback.cs
- SchemaImporterExtension.cs
- ClientSettingsProvider.cs
- DetailsViewDeleteEventArgs.cs
- ImpersonateTokenRef.cs
- ApplicationHost.cs
- ThreadAttributes.cs
- CodeArgumentReferenceExpression.cs
- FileSystemEnumerable.cs
- NameSpaceExtractor.cs
- CompositeActivityValidator.cs
- ConstraintManager.cs
- ProfileSettingsCollection.cs
- LockedHandleGlyph.cs
- InvalidPropValue.cs
- TrackBarRenderer.cs
- wgx_exports.cs
- DefaultBindingPropertyAttribute.cs
- MenuItem.cs
- XmlSchemaAll.cs
- ConfigurationCollectionAttribute.cs
- SimpleWebHandlerParser.cs
- CodeExporter.cs
- TimerEventSubscription.cs
- LinqMaximalSubtreeNominator.cs
- XmlEncoding.cs
- StyleHelper.cs
- SerializationException.cs
- InternalControlCollection.cs
- WebPartVerbCollection.cs
- InheritanceContextChangedEventManager.cs
- JapaneseLunisolarCalendar.cs
- remotingproxy.cs
- GenericWebPart.cs
- BookmarkEventArgs.cs
- IDQuery.cs
- WebAdminConfigurationHelper.cs
- ToolStripItemTextRenderEventArgs.cs
- PresentationTraceSources.cs
- SqlDataSourceStatusEventArgs.cs
- SqlCacheDependencySection.cs
- ScriptResourceMapping.cs
- TransformPattern.cs
- UnknownBitmapDecoder.cs
- QuaternionRotation3D.cs
- WindowsIdentity.cs
- CredentialCache.cs
- FontStretchConverter.cs
- WSHttpSecurityElement.cs
- NumberFormatInfo.cs
- DataGridCellsPresenter.cs
- DataPagerFieldCommandEventArgs.cs
- Misc.cs
- DataServicePagingProviderWrapper.cs
- AddressingProperty.cs
- PenThread.cs
- PropertyDescriptorComparer.cs
- FormsAuthenticationTicket.cs