Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / CreateSequence.cs / 1 / CreateSequence.cs
//----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//---------------------------------------------------------------------------
namespace System.ServiceModel.Channels
{
using System;
using System.ServiceModel;
using System.ServiceModel.Security;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
sealed class CreateSequence : BodyWriter
{
AddressingVersion addressingVersion;
IClientReliableChannelBinder binder;
UniqueId offerIdentifier;
bool ordered;
ReliableMessagingVersion reliableMessagingVersion;
CreateSequence() : base(true)
{
}
public CreateSequence(AddressingVersion addressingVersion, ReliableMessagingVersion reliableMessagingVersion,
bool ordered, IClientReliableChannelBinder binder, UniqueId offerIdentifier)
: base(true)
{
this.addressingVersion = addressingVersion;
this.reliableMessagingVersion = reliableMessagingVersion;
this.ordered = ordered;
this.binder = binder;
this.offerIdentifier = offerIdentifier;
}
public static CreateSequenceInfo Create(MessageVersion messageVersion,
ReliableMessagingVersion reliableMessagingVersion, ISecureConversationSession securitySession,
XmlDictionaryReader reader)
{
if (reader == null)
{
DiagnosticUtility.DebugAssert("Argument reader cannot be null.");
}
try
{
CreateSequenceInfo info = new CreateSequenceInfo();
WsrmFeb2005Dictionary wsrmFeb2005Dictionary = XD.WsrmFeb2005Dictionary;
XmlDictionaryString wsrmNs = WsrmIndex.GetNamespace(reliableMessagingVersion);
reader.ReadStartElement(wsrmFeb2005Dictionary.CreateSequence, wsrmNs);
info.AcksTo = EndpointAddress.ReadFrom(messageVersion.Addressing, reader, wsrmFeb2005Dictionary.AcksTo, wsrmNs);
if (reader.IsStartElement(wsrmFeb2005Dictionary.Expires, wsrmNs))
{
info.Expires = reader.ReadElementContentAsTimeSpan();
}
if (reader.IsStartElement(wsrmFeb2005Dictionary.Offer, wsrmNs))
{
reader.ReadStartElement();
reader.ReadStartElement(wsrmFeb2005Dictionary.Identifier, wsrmNs);
info.OfferIdentifier = reader.ReadContentAsUniqueId();
reader.ReadEndElement();
bool wsrm11 = reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11;
Wsrm11Dictionary wsrm11Dictionary = wsrm11 ? DXD.Wsrm11Dictionary : null;
if (wsrm11)
{
EndpointAddress endpoint = EndpointAddress.ReadFrom(messageVersion.Addressing, reader,
wsrm11Dictionary.Endpoint, wsrmNs);
if (endpoint.Uri != info.AcksTo.Uri)
{
string reason = SR.GetString(SR.CSRefusedAcksToMustEqualEndpoint);
Message faultReply = WsrmUtilities.CreateCSRefusedProtocolFault(messageVersion, reliableMessagingVersion, reason);
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(WsrmMessageInfo.CreateInternalFaultException(faultReply, reason, new ProtocolException(reason)));
}
}
if (reader.IsStartElement(wsrmFeb2005Dictionary.Expires, wsrmNs))
{
info.OfferExpires = reader.ReadElementContentAsTimeSpan();
}
if (wsrm11)
{
if (reader.IsStartElement(wsrm11Dictionary.IncompleteSequenceBehavior, wsrmNs))
{
string incompleteSequenceBehavior = reader.ReadElementContentAsString();
if ((incompleteSequenceBehavior != Wsrm11Strings.DiscardEntireSequence)
&& (incompleteSequenceBehavior != Wsrm11Strings.DiscardFollowingFirstGap)
&& (incompleteSequenceBehavior != Wsrm11Strings.NoDiscard))
{
string reason = SR.GetString(SR.CSRefusedInvalidIncompleteSequenceBehavior);
Message faultReply = WsrmUtilities.CreateCSRefusedProtocolFault(messageVersion, reliableMessagingVersion, reason);
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
WsrmMessageInfo.CreateInternalFaultException(faultReply, reason,
new ProtocolException(reason)));
}
// Otherwise ignore the value.
}
}
while (reader.IsStartElement())
{
reader.Skip();
}
reader.ReadEndElement();
}
// Check for security only if we expect a soap security session.
if (securitySession != null)
{
bool hasValidToken = false;
// Since the security element is amongst the extensible elements (i.e. there is no
// gaurantee of ordering or placement), a loop is required to attempt to parse the
// security element.
while (reader.IsStartElement())
{
if (securitySession.TryReadSessionTokenIdentifier(reader))
{
hasValidToken = true;
break;
}
reader.Skip();
}
if (!hasValidToken)
{
string reason = SR.GetString(SR.CSRefusedRequiredSecurityElementMissing);
Message faultReply = WsrmUtilities.CreateCSRefusedProtocolFault(messageVersion, reliableMessagingVersion, reason);
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(WsrmMessageInfo.CreateInternalFaultException(faultReply, reason, new ProtocolException(reason)));
}
}
while (reader.IsStartElement())
{
reader.Skip();
}
reader.ReadEndElement();
if (reader.IsStartElement())
{
string reason = SR.GetString(SR.CSRefusedUnexpectedElementAtEndOfCSMessage);
Message faultReply = WsrmUtilities.CreateCSRefusedProtocolFault(messageVersion, reliableMessagingVersion, reason);
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(WsrmMessageInfo.CreateInternalFaultException(faultReply, reason, new ProtocolException(reason)));
}
return info;
}
catch (XmlException e)
{
string reason = SR.GetString(SR.CouldNotParseWithAction, WsrmIndex.GetCreateSequenceActionString(reliableMessagingVersion));
Message faultReply = WsrmUtilities.CreateCSRefusedProtocolFault(messageVersion, reliableMessagingVersion, reason);
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(WsrmMessageInfo.CreateInternalFaultException(faultReply, reason, new ProtocolException(reason, e)));
}
}
protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
{
WsrmFeb2005Dictionary wsrmFeb2005Dictionary = XD.WsrmFeb2005Dictionary;
XmlDictionaryString wsrmNs = WsrmIndex.GetNamespace(this.reliableMessagingVersion);
writer.WriteStartElement(wsrmFeb2005Dictionary.CreateSequence, wsrmNs);
EndpointAddress localAddress = this.binder.LocalAddress;
localAddress.WriteTo(this.addressingVersion, writer, wsrmFeb2005Dictionary.AcksTo, wsrmNs);
if (this.offerIdentifier != null)
{
writer.WriteStartElement(wsrmFeb2005Dictionary.Offer, wsrmNs);
writer.WriteStartElement(wsrmFeb2005Dictionary.Identifier, wsrmNs);
writer.WriteValue(this.offerIdentifier);
writer.WriteEndElement();
if (this.reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11)
{
Wsrm11Dictionary wsrm11Dictionary = DXD.Wsrm11Dictionary;
localAddress.WriteTo(this.addressingVersion, writer, wsrm11Dictionary.Endpoint, wsrmNs);
writer.WriteStartElement(wsrm11Dictionary.IncompleteSequenceBehavior, wsrmNs);
writer.WriteValue(
this.ordered ? wsrm11Dictionary.DiscardFollowingFirstGap : wsrm11Dictionary.NoDiscard);
writer.WriteEndElement();
}
writer.WriteEndElement();
}
ISecureConversationSession securitySession = this.binder.GetInnerSession() as ISecureConversationSession;
if (securitySession != null)
securitySession.WriteSessionTokenIdentifier(writer);
writer.WriteEndElement();
}
}
}
// 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
- DataComponentGenerator.cs
- MiniLockedBorderGlyph.cs
- TreeViewHitTestInfo.cs
- MethodBody.cs
- TreeChangeInfo.cs
- COM2PictureConverter.cs
- SystemResourceKey.cs
- BasePropertyDescriptor.cs
- XPathAncestorQuery.cs
- ManagementScope.cs
- SqlRowUpdatingEvent.cs
- MessageFilterTable.cs
- PersonalizationStateQuery.cs
- StreamResourceInfo.cs
- MatrixValueSerializer.cs
- SafeNativeMethods.cs
- HttpWebRequest.cs
- DSASignatureDeformatter.cs
- TypeCollectionPropertyEditor.cs
- RelationshipConstraintValidator.cs
- SqlCacheDependencySection.cs
- SmiGettersStream.cs
- StylusDevice.cs
- XmlSchemaSimpleTypeRestriction.cs
- ChangeBlockUndoRecord.cs
- MultiAsyncResult.cs
- XmlLanguage.cs
- WebDisplayNameAttribute.cs
- XslException.cs
- ViewValidator.cs
- AuthenticatingEventArgs.cs
- ForEachDesigner.xaml.cs
- HtmlContainerControl.cs
- ButtonBaseAdapter.cs
- InstanceStoreQueryResult.cs
- SiteMap.cs
- EmbeddedMailObject.cs
- ChannelTerminatedException.cs
- ResourceSet.cs
- ToolStripDesignerUtils.cs
- StyleXamlParser.cs
- TypeName.cs
- WsdlImporterElementCollection.cs
- SystemPens.cs
- BrowserCapabilitiesCompiler.cs
- DeleteMemberBinder.cs
- FastEncoderWindow.cs
- XPathDocumentNavigator.cs
- OleDbPropertySetGuid.cs
- NotFiniteNumberException.cs
- WebException.cs
- ContractAdapter.cs
- Propagator.JoinPropagator.JoinPredicateVisitor.cs
- columnmapfactory.cs
- _SslSessionsCache.cs
- PasswordPropertyTextAttribute.cs
- OperandQuery.cs
- TemplatedWizardStep.cs
- SequenceRange.cs
- PropertyInfoSet.cs
- TemplateControl.cs
- DoubleAnimation.cs
- GACMembershipCondition.cs
- InfoCardSymmetricAlgorithm.cs
- InProcStateClientManager.cs
- Nullable.cs
- AsyncOperationContext.cs
- LaxModeSecurityHeaderElementInferenceEngine.cs
- StorageComplexPropertyMapping.cs
- FontResourceCache.cs
- ConfigurationElementCollection.cs
- Facet.cs
- Simplifier.cs
- Oid.cs
- InternalConfigHost.cs
- View.cs
- Currency.cs
- CodeEventReferenceExpression.cs
- TagNameToTypeMapper.cs
- HotSpotCollectionEditor.cs
- RectangleConverter.cs
- WebException.cs
- ResourceIDHelper.cs
- XslAstAnalyzer.cs
- ToolStripDesignerAvailabilityAttribute.cs
- ArraySubsetEnumerator.cs
- PolicyLevel.cs
- ListManagerBindingsCollection.cs
- SelectedCellsChangedEventArgs.cs
- EventMappingSettingsCollection.cs
- XmlLoader.cs
- Part.cs
- CategoriesDocumentFormatter.cs
- CodeGroup.cs
- TextUtf8RawTextWriter.cs
- SiteMapNodeItemEventArgs.cs
- UntypedNullExpression.cs
- SerializationSectionGroup.cs
- SqlClientPermission.cs
- DateTimeOffsetStorage.cs