Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Security / InfocardInteractiveChannelInitializer.cs / 1 / InfocardInteractiveChannelInitializer.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.ServiceModel.Security
{
using System.Collections.Generic;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Description;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.Runtime.Serialization;
using System.ServiceModel.Security;
public class InfocardInteractiveChannelInitializer : IInteractiveChannelInitializer
{
ClientCredentials credentials;
Binding binding;
public InfocardInteractiveChannelInitializer( ClientCredentials credentials, Binding binding )
{
this.credentials = credentials;
this.binding = binding;
}
public Binding Binding
{
get
{
return binding;
}
}
public virtual IAsyncResult BeginDisplayInitializationUI(IClientChannel channel, AsyncCallback callback, object state)
{
return new GetTokenUIAsyncResult(binding, channel, this.credentials, callback, state);
}
public virtual void EndDisplayInitializationUI(IAsyncResult result)
{
GetTokenUIAsyncResult.End(result);
}
}
internal class GetTokenUIAsyncResult :AsyncResult
{
IClientChannel proxy;
ClientCredentials credentials;
Uri relyingPartyIssuer;
bool requiresInfoCard;
Binding binding;
static AsyncCallback callback = DiagnosticUtility.ThunkAsyncCallback(new AsyncCallback(GetTokenUIAsyncResult.Callback));
internal GetTokenUIAsyncResult(Binding binding,
IClientChannel channel,
ClientCredentials credentials,
AsyncCallback callback,
object state)
: base(callback, state)
{
this.credentials = credentials;
this.proxy = channel;
this.binding = binding;
this.CallBegin(true);
}
void CallBegin(bool completedSynchronously)
{
IAsyncResult result = null;
Exception exception = null;
try
{
CardSpacePolicyElement[ ] chain;
SecurityTokenManager tokenManager = credentials.CreateSecurityTokenManager();
requiresInfoCard = InfoCardHelper.IsInfocardRequired(binding, credentials, tokenManager, proxy.RemoteAddress, out chain, out relyingPartyIssuer);
MessageSecurityVersion bindingSecurityVersion = InfoCardHelper.GetBindingSecurityVersionOrDefault(binding);
WSSecurityTokenSerializer tokenSerializer = WSSecurityTokenSerializer.DefaultInstance;
result = credentials.GetInfoCardTokenCallback.BeginInvoke(requiresInfoCard, chain, tokenManager.CreateSecurityTokenSerializer(bindingSecurityVersion.SecurityTokenVersion), callback, this);
}
catch (Exception e)
{
if (DiagnosticUtility.IsFatal(e))
{
throw;
}
exception = e;
}
if (exception == null)
{
if (!result.CompletedSynchronously)
{
return;
}
this.CallEnd(result, out exception);
}
if (exception != null)
{
return;
}
this.CallComplete(completedSynchronously, null);
}
static void Callback(IAsyncResult result)
{
if (result.CompletedSynchronously)
{
return;
}
GetTokenUIAsyncResult outer = (GetTokenUIAsyncResult)result.AsyncState;
Exception exception = null;
outer.CallEnd(result, out exception);
outer.CallComplete(false, exception);
}
void CallEnd(IAsyncResult result, out Exception exception)
{
try
{
SecurityToken token = credentials.GetInfoCardTokenCallback.EndInvoke(result);
ChannelParameterCollection channelParameters =
proxy.GetProperty();
if( null != channelParameters )
{
channelParameters.Add( new InfoCardChannelParameter( token, relyingPartyIssuer, requiresInfoCard ) );
}
exception = null;
}
catch (Exception e)
{
if (DiagnosticUtility.IsFatal(e))
{
throw;
}
exception = e;
}
}
void CallComplete(bool completedSynchronously, Exception exception)
{
this.Complete(completedSynchronously, exception);
}
internal static void End(IAsyncResult result)
{
AsyncResult.End(result);
}
}
}
// 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
- MLangCodePageEncoding.cs
- GlyphRun.cs
- XmlWrappingWriter.cs
- ExternalDataExchangeService.cs
- xmlsaver.cs
- ServerValidateEventArgs.cs
- TemplateBuilder.cs
- SymbolMethod.cs
- UserNameSecurityTokenParameters.cs
- Configuration.cs
- DataGridViewElement.cs
- SoapReflectionImporter.cs
- PackWebRequest.cs
- errorpatternmatcher.cs
- SiteMapNode.cs
- ExpanderAutomationPeer.cs
- SocketException.cs
- TypefaceMetricsCache.cs
- SmtpTransport.cs
- WaitForChangedResult.cs
- Behavior.cs
- ZipIOZip64EndOfCentralDirectoryLocatorBlock.cs
- WindowsImpersonationContext.cs
- ZipIOCentralDirectoryDigitalSignature.cs
- StringPropertyBuilder.cs
- TreeIterators.cs
- SimpleWorkerRequest.cs
- AbsoluteQuery.cs
- TrustManagerMoreInformation.cs
- NameGenerator.cs
- AnnotationObservableCollection.cs
- SQLInt32.cs
- AttributeQuery.cs
- FusionWrap.cs
- SolidBrush.cs
- CodeAccessPermission.cs
- InputLangChangeEvent.cs
- TextWriterEngine.cs
- UIInitializationException.cs
- CharEntityEncoderFallback.cs
- ValidationEventArgs.cs
- ScaleTransform.cs
- TypeReference.cs
- XPathSelectionIterator.cs
- DataGridColumnHeader.cs
- EmptyQuery.cs
- UInt64.cs
- Empty.cs
- ColumnResizeUndoUnit.cs
- FileNotFoundException.cs
- CodeTypeDeclaration.cs
- Input.cs
- DrawItemEvent.cs
- TdsParserSessionPool.cs
- HtmlMeta.cs
- ScrollProperties.cs
- CalendarDataBindingHandler.cs
- DataKeyArray.cs
- SqlDelegatedTransaction.cs
- invalidudtexception.cs
- DataGridViewCellValidatingEventArgs.cs
- MediaScriptCommandRoutedEventArgs.cs
- ExpressionNormalizer.cs
- SQLRoleProvider.cs
- SpnEndpointIdentity.cs
- DeflateEmulationStream.cs
- SecUtil.cs
- BitmapEffectvisualstate.cs
- SrgsSubset.cs
- Byte.cs
- JsonDeserializer.cs
- GridViewEditEventArgs.cs
- XmlSchemaNotation.cs
- _FtpControlStream.cs
- _MultipleConnectAsync.cs
- XmlNavigatorStack.cs
- WindowPatternIdentifiers.cs
- ImageListUtils.cs
- DataSourceProvider.cs
- IgnoreDataMemberAttribute.cs
- CodeSnippetExpression.cs
- HelloOperationCD1AsyncResult.cs
- DebugControllerThread.cs
- SpnEndpointIdentityExtension.cs
- XmlUrlEditor.cs
- Int16KeyFrameCollection.cs
- FlowDocumentScrollViewer.cs
- RotateTransform.cs
- CodeAccessSecurityEngine.cs
- StrokeNodeEnumerator.cs
- EntityObject.cs
- XPathItem.cs
- base64Transforms.cs
- SmiEventSink.cs
- EntityContainer.cs
- SizeFConverter.cs
- AnnotationResourceCollection.cs
- RevocationPoint.cs
- TraceListener.cs
- Constraint.cs