Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / OneWayBindingElement.cs / 1 / OneWayBindingElement.cs
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel.Channels
{
using System.Collections.Generic;
using System.ServiceModel;
using System.Runtime.Serialization;
using System.Xml;
using System.ServiceModel.Description;
using System.ServiceModel.Security;
public sealed class OneWayBindingElement : BindingElement,
IPolicyExportExtension
{
ChannelPoolSettings channelPoolSettings;
bool packetRoutable;
int maxAcceptedChannels;
public OneWayBindingElement()
{
this.channelPoolSettings = new ChannelPoolSettings();
this.packetRoutable = OneWayDefaults.PacketRoutable;
this.maxAcceptedChannels = OneWayDefaults.MaxAcceptedChannels;
}
OneWayBindingElement(OneWayBindingElement elementToBeCloned)
: base(elementToBeCloned)
{
this.channelPoolSettings = elementToBeCloned.ChannelPoolSettings.Clone();
this.packetRoutable = elementToBeCloned.PacketRoutable;
this.maxAcceptedChannels = elementToBeCloned.maxAcceptedChannels;
}
public ChannelPoolSettings ChannelPoolSettings
{
get
{
return this.channelPoolSettings;
}
}
// server
public int MaxAcceptedChannels
{
get
{
return this.maxAcceptedChannels;
}
set
{
if (value <= 0)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
SR.GetString(SR.ValueMustBePositive)));
this.maxAcceptedChannels = value;
}
}
public bool PacketRoutable
{
get
{
return this.packetRoutable;
}
set
{
this.packetRoutable = value;
}
}
public override BindingElement Clone()
{
return new OneWayBindingElement(this);
}
public override IChannelFactory BuildChannelFactory(BindingContext context)
{
if (context == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
}
if (typeof(TChannel) != typeof(IOutputChannel))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("TChannel",
SR.GetString(SR.ChannelTypeNotSupported, typeof(TChannel)));
}
// Prefer IDuplexSessionChannel
if (context.CanBuildInnerChannelFactory())
{
return (IChannelFactory)(object)new DuplexSessionOneWayChannelFactory(this, context);
}
// Followed by IRequestChannel
if (context.CanBuildInnerChannelFactory())
{
return (IChannelFactory)(object)new RequestOneWayChannelFactory(this, context);
}
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
#pragma warning suppress 56506 // context.Binding will never be null.
new InvalidOperationException(SR.GetString(SR.OneWayInternalTypeNotSupported, context.Binding.Name)));
}
public override IChannelListener BuildChannelListener(BindingContext context)
{
if (context == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
}
if (typeof(TChannel) != typeof(IInputChannel))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("TChannel",
SR.GetString(SR.ChannelTypeNotSupported, typeof(TChannel)));
}
// Prefer IDuplexSessionChannel
if (context.CanBuildInnerChannelListener())
{
return (IChannelListener)(object)new DuplexSessionOneWayChannelListener(this, context);
}
// Followed by IRequestChannel
if (context.CanBuildInnerChannelListener())
{
return (IChannelListener)(object)new ReplyOneWayChannelListener(this, context);
}
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
#pragma warning suppress 56506 // context.Binding will never be null.
new InvalidOperationException(SR.GetString(SR.OneWayInternalTypeNotSupported, context.Binding.Name)));
}
public override bool CanBuildChannelFactory(BindingContext context)
{
if (context == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
}
if (typeof(TChannel) != typeof(IOutputChannel))
{
return false;
}
// we can convert IDuplexSessionChannel
if (context.Clone().CanBuildInnerChannelFactory())
{
return true;
}
// and also IRequestChannel
if (context.CanBuildInnerChannelFactory())
{
return true;
}
return false;
}
public override bool CanBuildChannelListener(BindingContext context)
{
if (context == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
}
if (typeof(TChannel) != typeof(IInputChannel))
{
return false;
}
// we can convert IDuplexSessionChannel
if (context.Clone().CanBuildInnerChannelListener())
{
return true;
}
// and also IRequestChannel
if (context.CanBuildInnerChannelListener())
{
return true;
}
return false;
}
static MessagePartSpecification oneWaySignedMessageParts;
static MessagePartSpecification OneWaySignedMessageParts
{
get
{
if (oneWaySignedMessageParts == null)
{
MessagePartSpecification tempSignedMessageParts = new MessagePartSpecification(
new XmlQualifiedName(DotNetOneWayStrings.HeaderName, DotNetOneWayStrings.Namespace)
);
tempSignedMessageParts.MakeReadOnly();
oneWaySignedMessageParts = tempSignedMessageParts;
}
return oneWaySignedMessageParts;
}
}
public override T GetProperty(BindingContext context)
{
if (context == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
}
// make sure our Datagram header is signed
if (typeof(T) == typeof(ChannelProtectionRequirements))
{
ChannelProtectionRequirements myRequirements = new ChannelProtectionRequirements();
if (PacketRoutable)
{
myRequirements.IncomingSignatureParts.AddParts(OneWaySignedMessageParts);
myRequirements.OutgoingSignatureParts.AddParts(OneWaySignedMessageParts);
}
ChannelProtectionRequirements innerRequirements = context.GetInnerProperty();
if (innerRequirements != null)
{
myRequirements.Add(innerRequirements);
}
return (T)(object)myRequirements;
}
else
{
return context.GetInnerProperty();
}
}
internal override bool IsMatch(BindingElement b)
{
if (b == null)
{
return false;
}
OneWayBindingElement oneWayBindingElement = b as OneWayBindingElement;
if (oneWayBindingElement == null)
{
return false;
}
if (!this.channelPoolSettings.IsMatch(oneWayBindingElement.ChannelPoolSettings))
{
return false;
}
if (this.packetRoutable != oneWayBindingElement.PacketRoutable)
{
return false;
}
if (this.maxAcceptedChannels != oneWayBindingElement.MaxAcceptedChannels)
{
return false;
}
return true;
}
void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context)
{
if (context == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
}
if (context.BindingElements != null)
{
OneWayBindingElement oneWay = context.BindingElements.Find();
if (oneWay != null)
{
// base assertion
XmlDocument doc = new XmlDocument();
XmlElement assertion = doc.CreateElement(OneWayPolicyConstants.Prefix,
OneWayPolicyConstants.OneWay, OneWayPolicyConstants.Namespace);
if (oneWay.PacketRoutable)
{
// add nested packet routable assertion
XmlElement child = doc.CreateElement(OneWayPolicyConstants.Prefix, OneWayPolicyConstants.PacketRoutable, OneWayPolicyConstants.Namespace);
assertion.AppendChild(child);
}
context.GetBindingAssertions().Add(assertion);
}
}
}
}
}
// 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
- AssemblyName.cs
- ColumnClickEvent.cs
- TypeGeneratedEventArgs.cs
- __TransparentProxy.cs
- XmlSchema.cs
- CachedFontFace.cs
- JsonSerializer.cs
- EnumUnknown.cs
- SqlFactory.cs
- SessionParameter.cs
- HtmlInputButton.cs
- ProcessModelSection.cs
- DragDropManager.cs
- ECDsa.cs
- Point.cs
- PathSegmentCollection.cs
- DataReaderContainer.cs
- FamilyTypefaceCollection.cs
- SchemaSetCompiler.cs
- SaveFileDialogDesigner.cs
- Vector3dCollection.cs
- DataGridViewColumnConverter.cs
- ComponentGlyph.cs
- EventListener.cs
- SQLInt16.cs
- ScrollItemPattern.cs
- AnimationLayer.cs
- COSERVERINFO.cs
- TransferMode.cs
- DesignerHierarchicalDataSourceView.cs
- dtdvalidator.cs
- DelimitedListTraceListener.cs
- ConstrainedDataObject.cs
- tabpagecollectioneditor.cs
- Imaging.cs
- ReferencedCollectionType.cs
- WebPartDisplayMode.cs
- PropertyRecord.cs
- CanExecuteRoutedEventArgs.cs
- ProbeMatchesApril2005.cs
- CodeConstructor.cs
- SqlClientWrapperSmiStream.cs
- EntityCommandCompilationException.cs
- LinkedList.cs
- WebPartChrome.cs
- BufferedGraphicsManager.cs
- FormClosedEvent.cs
- WindowsFormsSectionHandler.cs
- Bits.cs
- XmlSchemaExporter.cs
- WpfPayload.cs
- XmlSignatureProperties.cs
- GZipStream.cs
- PathFigureCollection.cs
- MembershipPasswordException.cs
- WebServiceFaultDesigner.cs
- DataGrid.cs
- SettingsPropertyValue.cs
- ChtmlLinkAdapter.cs
- WindowsListBox.cs
- DetailsViewUpdatedEventArgs.cs
- FixedDocumentSequencePaginator.cs
- JoinSymbol.cs
- XPathScanner.cs
- Application.cs
- PageAsyncTask.cs
- ChangeConflicts.cs
- AspNetSynchronizationContext.cs
- Visual3D.cs
- MemberMaps.cs
- QilVisitor.cs
- OleDbErrorCollection.cs
- CodeCatchClauseCollection.cs
- InstanceDataCollection.cs
- NavigationCommands.cs
- ZipPackagePart.cs
- NameValuePermission.cs
- SqlDataSourceFilteringEventArgs.cs
- InsufficientMemoryException.cs
- ColorConvertedBitmapExtension.cs
- AttachedPropertyBrowsableWhenAttributePresentAttribute.cs
- ViewGenerator.cs
- PatternMatcher.cs
- filewebresponse.cs
- LogicalExpr.cs
- GlobalProxySelection.cs
- FreeFormDesigner.cs
- GridViewEditEventArgs.cs
- PrintPreviewDialog.cs
- XmlSchemaParticle.cs
- ReturnEventArgs.cs
- SplineQuaternionKeyFrame.cs
- sqlnorm.cs
- CurrencyManager.cs
- InstancePersistenceCommand.cs
- RegexStringValidatorAttribute.cs
- ReferencedAssembly.cs
- XamlInterfaces.cs
- IteratorFilter.cs
- IsolatedStorage.cs