Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / ChannelRequirements.cs / 1 / ChannelRequirements.cs
//---------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Channels { using System.Collections.Generic; using System.ServiceModel.Dispatcher; using System.ServiceModel.Description; using System.Globalization; using System.Text; struct ChannelRequirements { public bool usesInput; public bool usesReply; public bool usesOutput; public bool usesRequest; public SessionMode sessionMode; public static void ComputeContractRequirements(ContractDescription contractDescription, out ChannelRequirements requirements) { requirements = new ChannelRequirements(); requirements.usesInput = false; requirements.usesReply = false; requirements.usesOutput = false; requirements.usesRequest = false; requirements.sessionMode = contractDescription.SessionMode; for (int i = 0; i < contractDescription.Operations.Count; i++) { OperationDescription operation = contractDescription.Operations[i]; bool oneWay = (operation.IsOneWay); if (!operation.IsServerInitiated()) { if (oneWay) { requirements.usesInput = true; } else { requirements.usesReply = true; } } else { if (oneWay) { requirements.usesOutput = true; } else { requirements.usesRequest = true; } } } } public static Type[] ComputeRequiredChannels(ref ChannelRequirements requirements) { if (requirements.usesOutput || requirements.usesRequest) { switch (requirements.sessionMode) { case SessionMode.Allowed: return new Type[] { typeof(IDuplexChannel), typeof(IDuplexSessionChannel), }; case SessionMode.Required: return new Type[] { typeof(IDuplexSessionChannel), }; case SessionMode.NotAllowed: return new Type[] { typeof(IDuplexChannel), }; } } else if (requirements.usesInput && requirements.usesReply) { switch (requirements.sessionMode) { case SessionMode.Allowed: return new Type[] { typeof(IRequestChannel), typeof(IRequestSessionChannel), typeof(IDuplexChannel), typeof(IDuplexSessionChannel), }; case SessionMode.Required: return new Type[] { typeof(IRequestSessionChannel), typeof(IDuplexSessionChannel), }; case SessionMode.NotAllowed: return new Type[] { typeof(IRequestChannel), typeof(IDuplexChannel), }; } } else if (requirements.usesInput) { switch (requirements.sessionMode) { case SessionMode.Allowed: return new Type[] { typeof(IOutputChannel), typeof(IOutputSessionChannel), typeof(IRequestChannel), typeof(IRequestSessionChannel), typeof(IDuplexChannel), typeof(IDuplexSessionChannel), }; case SessionMode.Required: return new Type[] { typeof(IOutputSessionChannel), typeof(IRequestSessionChannel), typeof(IDuplexSessionChannel), }; case SessionMode.NotAllowed: return new Type[] { typeof(IOutputChannel), typeof(IRequestChannel), typeof(IDuplexChannel), }; } } else if (requirements.usesReply) { switch (requirements.sessionMode) { case SessionMode.Allowed: return new Type[] { typeof(IRequestChannel), typeof(IRequestSessionChannel), typeof(IDuplexChannel), typeof(IDuplexSessionChannel), }; case SessionMode.Required: return new Type[] { typeof(IRequestSessionChannel), typeof(IDuplexSessionChannel), }; case SessionMode.NotAllowed: return new Type[] { typeof(IRequestChannel), typeof(IDuplexChannel), }; } } else { switch (requirements.sessionMode) { case SessionMode.Allowed: return new Type[] { typeof(IOutputSessionChannel), typeof(IOutputChannel), typeof(IRequestSessionChannel), typeof(IRequestChannel), typeof(IDuplexChannel), typeof(IDuplexSessionChannel), }; case SessionMode.Required: return new Type[] { typeof(IOutputSessionChannel), typeof(IRequestSessionChannel), typeof(IDuplexSessionChannel), }; case SessionMode.NotAllowed: return new Type[] { typeof(IOutputChannel), typeof(IRequestChannel), typeof(IDuplexChannel), }; } } return null; } public static bool IsSessionful(Type channelType) { return (channelType == typeof(IDuplexSessionChannel) || channelType == typeof(IOutputSessionChannel) || channelType == typeof(IInputSessionChannel) || channelType == typeof(IReplySessionChannel) || channelType == typeof(IRequestSessionChannel)); } public static bool IsOneWay(Type channelType) { return (channelType == typeof(IOutputChannel) || channelType == typeof(IInputChannel) || channelType == typeof(IInputSessionChannel) || channelType == typeof(IOutputSessionChannel)); } public static bool IsRequestReply(Type channelType) { return (channelType == typeof(IRequestChannel) || channelType == typeof(IReplyChannel) || channelType == typeof(IReplySessionChannel) || channelType == typeof(IRequestSessionChannel)); } public static bool IsDuplex(Type channelType) { return (channelType == typeof(IDuplexChannel) || channelType == typeof(IDuplexSessionChannel)); } public static Exception CantCreateListenerException(IEnumerablesupportedChannels, IEnumerable requiredChannels, string bindingName) { string contractChannelTypesString = ""; string bindingChannelTypesString = ""; Exception exception = ChannelRequirements.BindingContractMismatchException(supportedChannels, requiredChannels, bindingName, ref contractChannelTypesString, ref bindingChannelTypesString); if (exception == null) { // none of the obvious speculations about the failure holds, so we fall back to the generic error message exception = new InvalidOperationException(SR.GetString(SR.EndpointListenerRequirementsCannotBeMetBy3, bindingName, contractChannelTypesString, bindingChannelTypesString)); } return exception; } public static Exception CantCreateChannelException(IEnumerable supportedChannels, IEnumerable requiredChannels, string bindingName) { string contractChannelTypesString = ""; string bindingChannelTypesString = ""; Exception exception = ChannelRequirements.BindingContractMismatchException(supportedChannels, requiredChannels, bindingName, ref contractChannelTypesString, ref bindingChannelTypesString); if (exception == null) { // none of the obvious speculations about the failure holds, so we fall back to the generic error message exception = new InvalidOperationException(SR.GetString(SR.CouldnTCreateChannelForType2, bindingName, contractChannelTypesString)); } return exception; } public static Exception BindingContractMismatchException(IEnumerable supportedChannels, IEnumerable requiredChannels, string bindingName, ref string contractChannelTypesString, ref string bindingChannelTypesString) { StringBuilder contractChannelTypes = new StringBuilder(); bool contractRequiresOneWay = true; bool contractRequiresRequestReply = true; bool contractRequiresDuplex = true; bool contractRequiresTwoWay = true; // request-reply or duplex bool contractRequiresSession = true; bool contractRequiresDatagram = true; foreach (Type channelType in requiredChannels) { if (contractChannelTypes.Length > 0) { contractChannelTypes.Append(CultureInfo.CurrentCulture.TextInfo.ListSeparator); contractChannelTypes.Append(" "); } string typeString = channelType.ToString(); contractChannelTypes.Append(typeString.Substring(typeString.LastIndexOf('.') + 1)); if (!ChannelRequirements.IsOneWay(channelType)) { contractRequiresOneWay = false; } if (!ChannelRequirements.IsRequestReply(channelType)) { contractRequiresRequestReply = false; } if (!ChannelRequirements.IsDuplex(channelType)) { contractRequiresDuplex = false; } if (!(ChannelRequirements.IsRequestReply(channelType) || ChannelRequirements.IsDuplex(channelType))) { contractRequiresTwoWay = false; } if (!ChannelRequirements.IsSessionful(channelType)) { contractRequiresSession = false; } else { contractRequiresDatagram = false; } } StringBuilder bindingChannelTypes = new StringBuilder(); bool bindingSupportsOneWay = false; bool bindingSupportsRequestReply = false; bool bindingSupportsDuplex = false; bool bindingSupportsSession = false; bool bindingSupportsDatagram = false; bool bindingSupportsAtLeastOneChannelType = false; foreach (Type channelType in supportedChannels) { bindingSupportsAtLeastOneChannelType = true; if (bindingChannelTypes.Length > 0) { bindingChannelTypes.Append(CultureInfo.CurrentCulture.TextInfo.ListSeparator); bindingChannelTypes.Append(" "); } string typeString = channelType.ToString(); bindingChannelTypes.Append(typeString.Substring(typeString.LastIndexOf('.') + 1)); if (ChannelRequirements.IsOneWay(channelType)) { bindingSupportsOneWay = true; } if (ChannelRequirements.IsRequestReply(channelType)) { bindingSupportsRequestReply = true; } if (ChannelRequirements.IsDuplex(channelType)) { bindingSupportsDuplex = true; } if (ChannelRequirements.IsSessionful(channelType)) { bindingSupportsSession = true; } else { bindingSupportsDatagram = true; } } bool bindingSupportsTwoWay = bindingSupportsRequestReply || bindingSupportsDuplex; if (!bindingSupportsAtLeastOneChannelType) { return new InvalidOperationException(SR.GetString(SR.BindingDoesnTSupportAnyChannelTypes1, bindingName)); } if (contractRequiresSession && !bindingSupportsSession) { return new InvalidOperationException(SR.GetString(SR.BindingDoesnTSupportSessionButContractRequires1, bindingName)); } if (contractRequiresDatagram && !bindingSupportsDatagram) { return new InvalidOperationException(SR.GetString(SR.BindingDoesntSupportDatagramButContractRequires, bindingName)); } if (contractRequiresDuplex && !bindingSupportsDuplex) { return new InvalidOperationException(SR.GetString(SR.BindingDoesnTSupportDuplexButContractRequires1, bindingName)); } if (contractRequiresRequestReply && !bindingSupportsRequestReply) { return new InvalidOperationException(SR.GetString(SR.BindingDoesnTSupportRequestReplyButContract1, bindingName)); } if (contractRequiresOneWay && !bindingSupportsOneWay) { return new InvalidOperationException(SR.GetString(SR.BindingDoesnTSupportOneWayButContractRequires1, bindingName)); } if (contractRequiresTwoWay && !bindingSupportsTwoWay) { return new InvalidOperationException(SR.GetString(SR.BindingDoesnTSupportTwoWayButContractRequires1, bindingName)); } contractChannelTypesString = contractChannelTypes.ToString(); bindingChannelTypesString = bindingChannelTypes.ToString(); return null; } } } // 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
- DmlSqlGenerator.cs
- StackBuilderSink.cs
- ConfigurationValue.cs
- SecUtil.cs
- AnnotationDocumentPaginator.cs
- CLSCompliantAttribute.cs
- IISMapPath.cs
- ListBase.cs
- PathGeometry.cs
- XmlAttribute.cs
- DataTableTypeConverter.cs
- ChildTable.cs
- Quaternion.cs
- listitem.cs
- DBSqlParserColumnCollection.cs
- XsdDateTime.cs
- DebugHandleTracker.cs
- Point3DConverter.cs
- DataReceivedEventArgs.cs
- _FixedSizeReader.cs
- Membership.cs
- OpCodes.cs
- RoleManagerEventArgs.cs
- Pkcs7Signer.cs
- ColumnHeader.cs
- PropertyStore.cs
- WindowsListViewGroup.cs
- SqlReorderer.cs
- WebSysDescriptionAttribute.cs
- PocoEntityKeyStrategy.cs
- HtmlInputButton.cs
- FileDetails.cs
- InvokeMethodActivity.cs
- RowToFieldTransformer.cs
- ProcessHostMapPath.cs
- SimpleFieldTemplateUserControl.cs
- SizeAnimation.cs
- TableItemProviderWrapper.cs
- DataGridViewDataConnection.cs
- ResourceCollectionInfo.cs
- GridErrorDlg.cs
- SqlDataSourceConnectionPanel.cs
- MetadataPropertyAttribute.cs
- TCPClient.cs
- XmlSerializerOperationGenerator.cs
- NonDualMessageSecurityOverHttpElement.cs
- BinaryReader.cs
- DecimalStorage.cs
- PropertyTab.cs
- sitestring.cs
- UrlUtility.cs
- Vector3DAnimationBase.cs
- DesignerWebPartChrome.cs
- QueryParameter.cs
- DataGridViewCellStyleConverter.cs
- DocumentCollection.cs
- ConnectionProviderAttribute.cs
- LogAppendAsyncResult.cs
- DotExpr.cs
- ACL.cs
- QueryInterceptorAttribute.cs
- LayoutEvent.cs
- clipboard.cs
- LambdaCompiler.Binary.cs
- HttpModuleCollection.cs
- Stream.cs
- ExtensionSimplifierMarkupObject.cs
- SpeechEvent.cs
- LogReservationCollection.cs
- BufferedWebEventProvider.cs
- Simplifier.cs
- Ipv6Element.cs
- Shape.cs
- _OSSOCK.cs
- EventLogPermission.cs
- OleDbException.cs
- HtmlSelectionListAdapter.cs
- NullableConverter.cs
- StoryFragments.cs
- EntityDataSourceChangingEventArgs.cs
- MappedMetaModel.cs
- SchemaNotation.cs
- WebPartMinimizeVerb.cs
- AsyncOperationLifetimeManager.cs
- DecimalSumAggregationOperator.cs
- SmtpException.cs
- safemediahandle.cs
- OleDbInfoMessageEvent.cs
- ModelProperty.cs
- ContextStaticAttribute.cs
- NotFiniteNumberException.cs
- Matrix.cs
- IconBitmapDecoder.cs
- DataColumnMappingCollection.cs
- _Semaphore.cs
- DesignerVerb.cs
- VScrollProperties.cs
- JumpPath.cs
- ImageAttributes.cs
- SmiConnection.cs