Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / xsp / System / Web / Extensions / Compilation / WCFModel / AsmxEndpointPickerExtension.cs / 1 / AsmxEndpointPickerExtension.cs
//------------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
//
//-----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Security.Permissions;
using System.Web.Services.Description;
#if WEB_EXTENSIONS_CODE
namespace System.Web.Compilation.WCFModel
#else
namespace Microsoft.VSDesigner.WCFModel
#endif
{
///
/// Wsdl import extension to remove the soap1.2 endpoint for ASMX services.
/// By default, ASMX services expose two endpoints, soap & soap1.2. In order
/// to have easy-of-use-parity with VS2005 ASMX web service consumption
/// we remove one of the endpoints for this special case.
///
#if WEB_EXTENSIONS_CODE
[PermissionSet(SecurityAction.LinkDemand, Name="FullTrust"), PermissionSet(SecurityAction.InheritanceDemand, Name="FullTrust")]
internal class AsmxEndpointPickerExtension : System.ServiceModel.Description.IWsdlImportExtension
#else
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust"), PermissionSet(SecurityAction.InheritanceDemand, Name = "FullTrust")]
internal class AsmxEndpointPickerExtension : System.ServiceModel.Description.IWsdlImportExtension
#endif
{
void System.ServiceModel.Description.IWsdlImportExtension.ImportContract(System.ServiceModel.Description.WsdlImporter importer, System.ServiceModel.Description.WsdlContractConversionContext context)
{
// We don't really care...
}
void System.ServiceModel.Description.IWsdlImportExtension.ImportEndpoint(System.ServiceModel.Description.WsdlImporter importer, System.ServiceModel.Description.WsdlEndpointConversionContext context)
{
// We don't really care...
}
///
/// Remove the Soap1.2 endpoint for ASMX web services if the service exposes
/// both a soap and a soap 1.2 endpoint
///
/// WSDL documents to modify
/// Ignored
/// Ignored
void System.ServiceModel.Description.IWsdlImportExtension.BeforeImport(System.Web.Services.Description.ServiceDescriptionCollection wsdlDocuments, System.Xml.Schema.XmlSchemaSet xmlSchemas, System.Collections.Generic.ICollection policy)
{
if (wsdlDocuments == null)
{
throw new ArgumentNullException("wsdlDocuments");
}
foreach (ServiceDescription document in wsdlDocuments)
{
foreach (Service service in document.Services)
{
// We only touch services that have exactly two endpoints
// (soap & soap 1.2)
if (service.Ports.Count != 2) continue;
Port portToDelete = null;
// Check both ports to see if they are a soap & soap 1.2 pair
if (IsSoapAsmxPort(typeof(SoapAddressBinding), service.Ports[0]) && IsSoapAsmxPort(typeof(Soap12AddressBinding), service.Ports[1]))
{
portToDelete = service.Ports[1];
}
else if (IsSoapAsmxPort(typeof(SoapAddressBinding), service.Ports[1]) && IsSoapAsmxPort(typeof(Soap12AddressBinding), service.Ports[0]))
{
portToDelete = service.Ports[0];
}
if (portToDelete != null)
{
service.Ports.Remove(portToDelete);
if (portToDelete.Binding != null)
{
// Find any associated bindings so that we can remove
// them as well...
List bindingsToDelete = new List();
foreach (Binding binding in document.Bindings)
{
if (String.Equals(binding.Name, portToDelete.Binding.Name, StringComparison.Ordinal))
{
bindingsToDelete.Add(binding);
}
}
foreach (Binding bindingToDelete in bindingsToDelete)
{
document.Bindings.Remove(bindingToDelete);
}
}
}
}
}
}
///
/// Is the given port an ASMX endpoint with the given SOAP address type?
///
///
///
///
private bool IsSoapAsmxPort(System.Type addressType, Port port)
{
SoapAddressBinding addressBinding = port.Extensions.Find(addressType) as SoapAddressBinding;
if (addressBinding != null && addressBinding.GetType() == addressType && IsAsmxUri(addressBinding.Location))
{
return true;
}
else
{
return false;
}
}
///
/// Is the given location an URL that has a .asmx file extension
///
///
///
private bool IsAsmxUri(string location)
{
Uri uri = null;
// Invalid URI - that can't be an ASMX service...
if (!System.Uri.TryCreate(location, UriKind.Absolute, out uri))
{
return false;
}
// Check if the "filename" part of the URL has a .asmx file extension
string[] segments = uri.Segments;
if (segments.Length > 0)
{
try
{
string fileName = segments[segments.Length - 1];
if (String.Equals(System.IO.Path.GetExtension(fileName), ".asmx", StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
catch (System.ArgumentException)
{
// This was most likely an invalid path... well, let's just treat this as if
// this is not an ASMX endpoint...
}
}
return false;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
//
//-----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Security.Permissions;
using System.Web.Services.Description;
#if WEB_EXTENSIONS_CODE
namespace System.Web.Compilation.WCFModel
#else
namespace Microsoft.VSDesigner.WCFModel
#endif
{
///
/// Wsdl import extension to remove the soap1.2 endpoint for ASMX services.
/// By default, ASMX services expose two endpoints, soap & soap1.2. In order
/// to have easy-of-use-parity with VS2005 ASMX web service consumption
/// we remove one of the endpoints for this special case.
///
#if WEB_EXTENSIONS_CODE
[PermissionSet(SecurityAction.LinkDemand, Name="FullTrust"), PermissionSet(SecurityAction.InheritanceDemand, Name="FullTrust")]
internal class AsmxEndpointPickerExtension : System.ServiceModel.Description.IWsdlImportExtension
#else
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust"), PermissionSet(SecurityAction.InheritanceDemand, Name = "FullTrust")]
internal class AsmxEndpointPickerExtension : System.ServiceModel.Description.IWsdlImportExtension
#endif
{
void System.ServiceModel.Description.IWsdlImportExtension.ImportContract(System.ServiceModel.Description.WsdlImporter importer, System.ServiceModel.Description.WsdlContractConversionContext context)
{
// We don't really care...
}
void System.ServiceModel.Description.IWsdlImportExtension.ImportEndpoint(System.ServiceModel.Description.WsdlImporter importer, System.ServiceModel.Description.WsdlEndpointConversionContext context)
{
// We don't really care...
}
///
/// Remove the Soap1.2 endpoint for ASMX web services if the service exposes
/// both a soap and a soap 1.2 endpoint
///
/// WSDL documents to modify
/// Ignored
/// Ignored
void System.ServiceModel.Description.IWsdlImportExtension.BeforeImport(System.Web.Services.Description.ServiceDescriptionCollection wsdlDocuments, System.Xml.Schema.XmlSchemaSet xmlSchemas, System.Collections.Generic.ICollection policy)
{
if (wsdlDocuments == null)
{
throw new ArgumentNullException("wsdlDocuments");
}
foreach (ServiceDescription document in wsdlDocuments)
{
foreach (Service service in document.Services)
{
// We only touch services that have exactly two endpoints
// (soap & soap 1.2)
if (service.Ports.Count != 2) continue;
Port portToDelete = null;
// Check both ports to see if they are a soap & soap 1.2 pair
if (IsSoapAsmxPort(typeof(SoapAddressBinding), service.Ports[0]) && IsSoapAsmxPort(typeof(Soap12AddressBinding), service.Ports[1]))
{
portToDelete = service.Ports[1];
}
else if (IsSoapAsmxPort(typeof(SoapAddressBinding), service.Ports[1]) && IsSoapAsmxPort(typeof(Soap12AddressBinding), service.Ports[0]))
{
portToDelete = service.Ports[0];
}
if (portToDelete != null)
{
service.Ports.Remove(portToDelete);
if (portToDelete.Binding != null)
{
// Find any associated bindings so that we can remove
// them as well...
List bindingsToDelete = new List();
foreach (Binding binding in document.Bindings)
{
if (String.Equals(binding.Name, portToDelete.Binding.Name, StringComparison.Ordinal))
{
bindingsToDelete.Add(binding);
}
}
foreach (Binding bindingToDelete in bindingsToDelete)
{
document.Bindings.Remove(bindingToDelete);
}
}
}
}
}
}
///
/// Is the given port an ASMX endpoint with the given SOAP address type?
///
///
///
///
private bool IsSoapAsmxPort(System.Type addressType, Port port)
{
SoapAddressBinding addressBinding = port.Extensions.Find(addressType) as SoapAddressBinding;
if (addressBinding != null && addressBinding.GetType() == addressType && IsAsmxUri(addressBinding.Location))
{
return true;
}
else
{
return false;
}
}
///
/// Is the given location an URL that has a .asmx file extension
///
///
///
private bool IsAsmxUri(string location)
{
Uri uri = null;
// Invalid URI - that can't be an ASMX service...
if (!System.Uri.TryCreate(location, UriKind.Absolute, out uri))
{
return false;
}
// Check if the "filename" part of the URL has a .asmx file extension
string[] segments = uri.Segments;
if (segments.Length > 0)
{
try
{
string fileName = segments[segments.Length - 1];
if (String.Equals(System.IO.Path.GetExtension(fileName), ".asmx", StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
catch (System.ArgumentException)
{
// This was most likely an invalid path... well, let's just treat this as if
// this is not an ASMX endpoint...
}
}
return false;
}
}
}
// 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
- COM2IProvidePropertyBuilderHandler.cs
- MultiSelectRootGridEntry.cs
- URI.cs
- CryptoKeySecurity.cs
- HwndStylusInputProvider.cs
- Selection.cs
- SerializableAuthorizationContext.cs
- FormViewModeEventArgs.cs
- EncoderParameters.cs
- EmissiveMaterial.cs
- RequestContext.cs
- IOException.cs
- ValidatorCompatibilityHelper.cs
- CacheOutputQuery.cs
- XmlStringTable.cs
- CustomTokenProvider.cs
- HighContrastHelper.cs
- TemplateControlParser.cs
- StreamWriter.cs
- XmlSchemaExporter.cs
- MarkupWriter.cs
- StringComparer.cs
- IIS7UserPrincipal.cs
- RemotingException.cs
- OleCmdHelper.cs
- ItemCheckedEvent.cs
- WebHttpEndpoint.cs
- SqlInfoMessageEvent.cs
- ProfileSection.cs
- ServiceMetadataBehavior.cs
- TimeSpanStorage.cs
- ProtocolsInstallComponent.cs
- SafeSecurityHelper.cs
- PointCollectionConverter.cs
- MessageDirection.cs
- ServiceBusyException.cs
- ListViewTableCell.cs
- LinearKeyFrames.cs
- CodeBinaryOperatorExpression.cs
- CatalogZoneBase.cs
- SqlClientWrapperSmiStream.cs
- DataColumnMappingCollection.cs
- RecommendedAsConfigurableAttribute.cs
- RuntimeEnvironment.cs
- NameValuePair.cs
- LambdaCompiler.Lambda.cs
- FixedSOMPageElement.cs
- ExpressionBuilderContext.cs
- XmlNamespaceManager.cs
- OdbcDataReader.cs
- TextTreeUndoUnit.cs
- SafePEFileHandle.cs
- DataRelation.cs
- HttpProfileBase.cs
- AssemblyResourceLoader.cs
- DurableErrorHandler.cs
- AsyncPostBackTrigger.cs
- DropSource.cs
- CompressEmulationStream.cs
- DataGridViewCellErrorTextNeededEventArgs.cs
- EntitySetBaseCollection.cs
- FrameworkContextData.cs
- RequestStatusBarUpdateEventArgs.cs
- ListItemCollection.cs
- Switch.cs
- WebReferenceOptions.cs
- PropertyChangeTracker.cs
- FloaterParagraph.cs
- _ListenerResponseStream.cs
- ImportContext.cs
- AccessDataSourceView.cs
- ScriptingRoleServiceSection.cs
- XmlValidatingReader.cs
- EventProviderWriter.cs
- ListenerConnectionDemuxer.cs
- Label.cs
- WebPartsSection.cs
- SecurityElement.cs
- XmlDataSourceView.cs
- DataRowComparer.cs
- WebServiceFault.cs
- FrameworkContextData.cs
- RelationalExpressions.cs
- AsymmetricAlgorithm.cs
- SqlFunctions.cs
- Context.cs
- DataSourceExpressionCollection.cs
- ItemChangedEventArgs.cs
- SmtpClient.cs
- DesignTimeParseData.cs
- UInt64.cs
- MinMaxParagraphWidth.cs
- Iis7Helper.cs
- RootNamespaceAttribute.cs
- CollectionViewGroup.cs
- TableParaClient.cs
- WmlSelectionListAdapter.cs
- ProjectedSlot.cs
- PingReply.cs
- SqlDataSourceDesigner.cs