Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / infocard / Service / managed / Microsoft / InfoCards / InfoCardMetadataExchangeClient.cs / 2 / InfoCardMetadataExchangeClient.cs
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace Microsoft.InfoCards
{
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Net;
using IDT = Microsoft.InfoCards.Diagnostics.InfoCardTrace;
using System.IO;
using System.Text;
internal class InfoCardMetadataExchangeClient :MetadataExchangeClient
{
HttpWebRequest m_currentHttpGetRequest;
object m_abortSync;
bool m_aborted;
IWebProxy m_proxy;
//
// Summary:
// Creates a HttpsTransportBindingelement for mex interactions
//
// Remarks:
// We are manually creating a CustomBinding as opposed to relying on
// new WSHttpBinding( SecurityMode.Transport ) ); which sets AuthenticationScheme
// to Negotiate by default. Another difference is that new WSHttpBinding inserts
// a irrelevant TransactionFlowBindingElement. This is "irrelevant" because
// TransactionFlowBindingElement doesn't yield a channel when Transactions = false.
// See CSDMain 7086 for details.
//
// Remarks: We're setting httpTransportBinding.AuthenticationScheme to Anonymous
// for all legs including IP/STS leg
//
public static CustomBinding CreateBindingForMex()
{
HttpsTransportBindingElement httpsTransport = new HttpsTransportBindingElement();
IDT.Assert(
AuthenticationSchemes.Anonymous == httpsTransport.AuthenticationScheme,
"AuthenticationScheme must be Anonymous and not NTLM/Negotiate" );
CustomBinding httpsBinding = new CustomBinding(
new TextMessageEncodingBindingElement(), //the same encoding used when WsHttpBinding is used
httpsTransport );
return httpsBinding;
}
public InfoCardMetadataExchangeClient()
: base( CreateBindingForMex() )
{
//
// We enforce CardSpace restrictions on the WSHttpBinding binding
// in the GetChannelFactory override
//
m_abortSync = new object();
}
public IWebProxy Proxy
{
set { m_proxy = value; }
}
public void Abort()
{
lock( m_abortSync )
{
if( null != m_currentHttpGetRequest )
{
m_currentHttpGetRequest.Abort();
}
else
{
ChannelFactory factory = base.GetChannelFactory(null,null,null);
if( null != factory )
{
factory.Abort();
}
}
m_aborted = true;
}
}
protected internal override HttpWebRequest GetWebRequest( System.Uri location, string dialect, string identifier )
{
if( 0 != String.Compare( location.Scheme, "https", StringComparison.OrdinalIgnoreCase ) )
{
throw IDT.ThrowHelperError( new TrustExchangeException(
SR.GetString( SR.NonHttpsURIFound, location.AbsoluteUri ) ) );
}
HttpWebRequest request = base.GetWebRequest( location, dialect, identifier );
IDT.Assert( null == request.Credentials, "No creds should be set" );
IDT.Assert( null != m_proxy, "Set the proxy value before creating a WebRequest" );
request.Proxy = m_proxy;
lock( m_abortSync )
{
//
// if we are already in an aborted state, ensure that the next request automatically aborts.
//
if( m_aborted )
{
request.Abort();
}
return (m_currentHttpGetRequest = request);
}
}
protected internal override ChannelFactory GetChannelFactory( EndpointAddress metadataAddress, string dialect, string identifier )
{
if( null != metadataAddress && 0 != String.Compare( metadataAddress.Uri.Scheme, "https", StringComparison.OrdinalIgnoreCase ) )
{
throw IDT.ThrowHelperError( new TrustExchangeException(
SR.GetString( SR.NonHttpsURIFound, metadataAddress.Uri.AbsoluteUri ) ) );
}
IDT.Assert( null != m_proxy, "Set the proxy value before creating a WebRequest" );
ChannelFactory factory = base.GetChannelFactory( metadataAddress, dialect, identifier );
//
// Can't set factory.Credentials.Windows.AllowNtlm = false;
// Exception thrown that the factory.Credentials.Windows
// "Object is immutable".
//
// WCF makes it read-only after the first leg in federation chain.
// This is probably to ensure that settings on the channelFactory do not
// change when multiple channels are created from the same channelFactory.
// This happens specifically in ChannelFactory.Open() (which can be triggered by opening a
// channel created by the factory)
//
factory.Endpoint.Binding = new CustomBinding(
Utility.UpdateProxyForHttpAndRestrictTransportBinding(
factory.Endpoint.Binding.CreateBindingElements(),
m_proxy,
true ) ); // Client auth on transport should be turned off for mex.
lock( m_abortSync )
{
//
// if we are already in an aborted state, ensure that the next request automatically aborts.
//
if( m_aborted )
{
factory.Abort();
}
}
return factory;
}
}
}
// 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
- DateBoldEvent.cs
- SerialErrors.cs
- ProfilePropertyMetadata.cs
- arclist.cs
- RequestStatusBarUpdateEventArgs.cs
- Vector3DCollectionValueSerializer.cs
- FileSystemWatcher.cs
- CustomCategoryAttribute.cs
- HelpKeywordAttribute.cs
- DataBindingHandlerAttribute.cs
- ListSortDescription.cs
- HttpListenerContext.cs
- SqlParameterizer.cs
- QilPatternVisitor.cs
- UrlMappingsModule.cs
- TCPListener.cs
- XmlAttribute.cs
- BooleanProjectedSlot.cs
- SafeLibraryHandle.cs
- TypeConvertions.cs
- XmlReflectionImporter.cs
- RenderingBiasValidation.cs
- DataMemberFieldEditor.cs
- DataGridViewColumnTypePicker.cs
- WorkflowPersistenceService.cs
- QueryCacheKey.cs
- DataObject.cs
- RectangleHotSpot.cs
- ArcSegment.cs
- ProfileModule.cs
- InvalidCastException.cs
- HttpWebResponse.cs
- SelectionService.cs
- TileModeValidation.cs
- ItemCollection.cs
- ObjectParameterCollection.cs
- Substitution.cs
- OutputBuffer.cs
- _HeaderInfo.cs
- FileChangeNotifier.cs
- AssemblyBuilder.cs
- VersionedStream.cs
- TracedNativeMethods.cs
- TraceHandlerErrorFormatter.cs
- QueryStringHandler.cs
- WebZone.cs
- TextViewBase.cs
- VisualStyleRenderer.cs
- SerializerProvider.cs
- MimeAnyImporter.cs
- RegistryExceptionHelper.cs
- UserValidatedEventArgs.cs
- SourceSwitch.cs
- BufferedReadStream.cs
- Main.cs
- ToolStripRenderer.cs
- Win32SafeHandles.cs
- _HeaderInfoTable.cs
- OdbcCommand.cs
- CurrentChangedEventManager.cs
- ToolStripActionList.cs
- _IPv4Address.cs
- TargetPerspective.cs
- SoapTypeAttribute.cs
- SaveFileDialog.cs
- mda.cs
- PointConverter.cs
- MeasurementDCInfo.cs
- Path.cs
- IndexedString.cs
- DrawingDrawingContext.cs
- ChooseAction.cs
- DPCustomTypeDescriptor.cs
- SmiRecordBuffer.cs
- FamilyTypeface.cs
- PropertyConverter.cs
- AnnotationDocumentPaginator.cs
- DataGridViewRowHeightInfoNeededEventArgs.cs
- SqlGenerator.cs
- oledbmetadatacollectionnames.cs
- EFColumnProvider.cs
- DateTimeOffset.cs
- PropertyMappingExceptionEventArgs.cs
- QueryReaderSettings.cs
- DiscoveryRequestHandler.cs
- TextCollapsingProperties.cs
- WhitespaceRuleReader.cs
- Deflater.cs
- XmlDataSourceView.cs
- XsltFunctions.cs
- DelegatingTypeDescriptionProvider.cs
- FixedDocument.cs
- __ComObject.cs
- TemplateBindingExtensionConverter.cs
- KeyboardDevice.cs
- IdentitySection.cs
- Bidi.cs
- TextElement.cs
- validationstate.cs
- AdRotator.cs