internal override bool IsMatch(BindingElement b) { if (b == null) { return(false); } TransactionFlowBindingElement txFlow = b as TransactionFlowBindingElement; if (txFlow == null) { return(false); } if (_transactions != txFlow._transactions) { return(false); } if (_issuedTokens != txFlow._issuedTokens) { return(false); } if (_transactionProtocol != txFlow._transactionProtocol) { return(false); } return(true); }
internal override bool IsMatch(BindingElement b) { if (b == null) { return(false); } TransactionFlowBindingElement element = b as TransactionFlowBindingElement; if (element == null) { return(false); } if (this.transactions != element.transactions) { return(false); } if (this.issuedTokens != element.issuedTokens) { return(false); } if (this.transactionProtocol != element.transactionProtocol) { return(false); } return(true); }
private TransactionFlowBindingElement(TransactionFlowBindingElement elementToBeCloned) : base(elementToBeCloned) { this.transactions = elementToBeCloned.transactions; this.issuedTokens = elementToBeCloned.issuedTokens; if (!System.ServiceModel.TransactionProtocol.IsDefined(elementToBeCloned.transactionProtocol)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(System.ServiceModel.SR.GetString("ConfigInvalidTransactionFlowProtocolValue", new object[] { elementToBeCloned.transactionProtocol.ToString() })); } this.transactionProtocol = elementToBeCloned.transactionProtocol; this.AllowWildcardAction = elementToBeCloned.AllowWildcardAction; }
TransactionFlowBindingElement EnsureBindingElement(PolicyConversionContext context) { TransactionFlowBindingElement settings = context.BindingElements.Find <TransactionFlowBindingElement>(); if (settings == null) { settings = new TransactionFlowBindingElement(false); context.BindingElements.Add(settings); } return(settings); }
private TransactionFlowBindingElement EnsureBindingElement(PolicyConversionContext context) { TransactionFlowBindingElement item = context.BindingElements.Find <TransactionFlowBindingElement>(); if (item == null) { item = new TransactionFlowBindingElement(false); context.BindingElements.Add(item); } return(item); }
void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context) { if (exporter == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("exporter"); } if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } TransactionFlowBindingElement bindingElement = context.BindingElements.Find <TransactionFlowBindingElement>(); if (bindingElement == null || !bindingElement.Transactions) { return; } XmlDocument doc = new XmlDocument(); XmlElement assertion = null; foreach (OperationDescription operation in context.Contract.Operations) { TransactionFlowAttribute contextParam = operation.Behaviors.Find <TransactionFlowAttribute>(); TransactionFlowOption txFlowOption = contextParam == null ? TransactionFlowOption.NotAllowed : contextParam.Transactions; // Transactions if (bindingElement.TransactionProtocol == TransactionProtocol.OleTransactions) { assertion = GetAssertion(doc, txFlowOption, TransactionPolicyStrings.OleTxTransactionsPrefix, TransactionPolicyStrings.OleTxTransactionsLocal, TransactionPolicyStrings.OleTxTransactionsNamespace, exporter.PolicyVersion.Namespace); } else if (bindingElement.TransactionProtocol == TransactionProtocol.WSAtomicTransactionOctober2004) { assertion = GetAssertion(doc, txFlowOption, TransactionPolicyStrings.WsatTransactionsPrefix, TransactionPolicyStrings.WsatTransactionsLocal, TransactionPolicyStrings.WsatTransactionsNamespace10, exporter.PolicyVersion.Namespace); } else if (bindingElement.TransactionProtocol == TransactionProtocol.WSAtomicTransaction11) { assertion = GetAssertion(doc, txFlowOption, TransactionPolicyStrings.WsatTransactionsPrefix, TransactionPolicyStrings.WsatTransactionsLocal, TransactionPolicyStrings.WsatTransactionsNamespace11, exporter.PolicyVersion.Namespace); } if (assertion != null) { context.GetOperationBindingAssertions(operation).Add(assertion); } } }
private void Initialize() { this.httpTransport = new HttpTransportBindingElement(); this.httpsTransport = new HttpsTransportBindingElement(); this.messageEncoding = WSMessageEncoding.Text; this.txFlow = GetDefaultTransactionFlowBindingElement(); this.session = new System.ServiceModel.Channels.ReliableSessionBindingElement(true); this.textEncoding = new TextMessageEncodingBindingElement(); this.textEncoding.MessageVersion = MessageVersion.Soap12WSAddressing10; this.mtomEncoding = new MtomMessageEncodingBindingElement(); this.mtomEncoding.MessageVersion = MessageVersion.Soap12WSAddressing10; this.reliableSession = new OptionalReliableSession(this.session); }
TransactionFlowBindingElement(TransactionFlowBindingElement elementToBeCloned) : base(elementToBeCloned) { this.transactions = elementToBeCloned.transactions; this.issuedTokens = elementToBeCloned.issuedTokens; if (!TransactionProtocol.IsDefined(elementToBeCloned.transactionProtocol)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.ConfigInvalidTransactionFlowProtocolValue, elementToBeCloned.transactionProtocol.ToString())); } this.transactionProtocol = elementToBeCloned.transactionProtocol; this.AllowWildcardAction = elementToBeCloned.AllowWildcardAction; }
private TransactionFlowBindingElement(TransactionFlowBindingElement elementToBeCloned) : base(elementToBeCloned) { _transactions = elementToBeCloned._transactions; _issuedTokens = elementToBeCloned._issuedTokens; if (!TransactionProtocol.IsDefined(elementToBeCloned._transactionProtocol)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(string.Format(SRServiceModel.ConfigInvalidTransactionFlowProtocolValue, elementToBeCloned._transactionProtocol.ToString())); } _transactionProtocol = elementToBeCloned._transactionProtocol; this.AllowWildcardAction = elementToBeCloned.AllowWildcardAction; }
void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context) { if (exporter == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("exporter"); } if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } TransactionFlowBindingElement element = context.BindingElements.Find <TransactionFlowBindingElement>(); if ((element != null) && element.Transactions) { XmlDocument doc = new XmlDocument(); XmlElement item = null; foreach (OperationDescription description in context.Contract.Operations) { TransactionFlowAttribute attribute = description.Behaviors.Find <TransactionFlowAttribute>(); TransactionFlowOption option = (attribute == null) ? TransactionFlowOption.NotAllowed : attribute.Transactions; if (element.TransactionProtocol == System.ServiceModel.TransactionProtocol.OleTransactions) { item = this.GetAssertion(doc, option, "oletx", "OleTxAssertion", "http://schemas.microsoft.com/ws/2006/02/tx/oletx", exporter.PolicyVersion.Namespace); } else if (element.TransactionProtocol == System.ServiceModel.TransactionProtocol.WSAtomicTransactionOctober2004) { item = this.GetAssertion(doc, option, "wsat", "ATAssertion", "http://schemas.xmlsoap.org/ws/2004/10/wsat", exporter.PolicyVersion.Namespace); } else if (element.TransactionProtocol == System.ServiceModel.TransactionProtocol.WSAtomicTransaction11) { item = this.GetAssertion(doc, option, "wsat", "ATAssertion", "http://docs.oasis-open.org/ws-tx/wsat/2006/06", exporter.PolicyVersion.Namespace); } if (item != null) { context.GetOperationBindingAssertions(description).Add(item); } } } }
void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext context) { if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } // foreach property, we keep track of // - everyoneAgreesAbout: all operations agree on a value // - anOperationCaresAbout: at least one operation has expressed a preference // - agreed value itself (which only matters if anOperationCaresAbout && everyoneAgrees) bool everyoneAgreesAboutTransactions = true; bool everyoneAgreesAboutTransactionProtocol = true; TransactionFlowOption agreedTransactions = TransactionFlowOption.NotAllowed; TransactionProtocol agreedTransactionProtocol = TransactionFlowDefaults.TransactionProtocol; bool anOperationCaresAboutTransactions = false; bool anOperationCaresAboutTransactionProtocol = false; XmlElement oleTxTransactionsAssertion = null; XmlElement wsatTransactionsAssertion = null; foreach (OperationDescription operation in context.Contract.Operations) { ICollection <XmlElement> operationAssertions = context.GetOperationBindingAssertions(operation); foreach (XmlElement element in operationAssertions) { if (element.NamespaceURI == TransactionPolicyStrings.OleTxTransactionsNamespace && element.LocalName == TransactionPolicyStrings.OleTxTransactionsLocal) { oleTxTransactionsAssertion = element; TransactionFlowOption txFlow = GetOption(element, true); UpdateTransactionFlowAtribute(operation, txFlow); TrackAgreement(ref everyoneAgreesAboutTransactions, txFlow, ref agreedTransactions, ref anOperationCaresAboutTransactions); TrackAgreementTransactionProtocol(ref everyoneAgreesAboutTransactionProtocol, TransactionProtocol.OleTransactions, ref agreedTransactionProtocol, ref anOperationCaresAboutTransactionProtocol); } else if (element.NamespaceURI == TransactionPolicyStrings.WsatTransactionsNamespace10 && element.LocalName == TransactionPolicyStrings.WsatTransactionsLocal) { wsatTransactionsAssertion = element; TransactionFlowOption txFlow = GetOption(element, true); UpdateTransactionFlowAtribute(operation, txFlow); TrackAgreement(ref everyoneAgreesAboutTransactions, txFlow, ref agreedTransactions, ref anOperationCaresAboutTransactions); TrackAgreementTransactionProtocol(ref everyoneAgreesAboutTransactionProtocol, TransactionProtocol.WSAtomicTransactionOctober2004, ref agreedTransactionProtocol, ref anOperationCaresAboutTransactionProtocol); } else if (element.NamespaceURI == TransactionPolicyStrings.WsatTransactionsNamespace11 && element.LocalName == TransactionPolicyStrings.WsatTransactionsLocal) { wsatTransactionsAssertion = element; TransactionFlowOption txFlow = GetOption(element, false); UpdateTransactionFlowAtribute(operation, txFlow); TrackAgreement(ref everyoneAgreesAboutTransactions, txFlow, ref agreedTransactions, ref anOperationCaresAboutTransactions); TrackAgreementTransactionProtocol(ref everyoneAgreesAboutTransactionProtocol, TransactionProtocol.WSAtomicTransaction11, ref agreedTransactionProtocol, ref anOperationCaresAboutTransactionProtocol); } } // remove any imported assertions. if (oleTxTransactionsAssertion != null) { operationAssertions.Remove(oleTxTransactionsAssertion); } if (wsatTransactionsAssertion != null) { operationAssertions.Remove(wsatTransactionsAssertion); } } // setup the ContextFlowBindingElement (if needed) with any agreed-on information if (anOperationCaresAboutTransactions) { TransactionFlowBindingElement tfbe = EnsureBindingElement(context); tfbe.Transactions = true; if (anOperationCaresAboutTransactionProtocol && everyoneAgreesAboutTransactionProtocol) { tfbe.TransactionProtocol = agreedTransactionProtocol; } else if (anOperationCaresAboutTransactionProtocol) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException( SR.GetString(SR.SFxCannotHaveDifferentTransactionProtocolsInOneBinding))); } } }
private void InitializeFrom(HttpTransportBindingElement transport, MessageEncodingBindingElement encoding, System.ServiceModel.Channels.TransactionFlowBindingElement txFlow, System.ServiceModel.Channels.ReliableSessionBindingElement session) { this.BypassProxyOnLocal = transport.BypassProxyOnLocal; this.HostNameComparisonMode = transport.HostNameComparisonMode; this.MaxBufferPoolSize = transport.MaxBufferPoolSize; this.MaxReceivedMessageSize = transport.MaxReceivedMessageSize; this.ProxyAddress = transport.ProxyAddress; this.UseDefaultWebProxy = transport.UseDefaultWebProxy; if (encoding is TextMessageEncodingBindingElement) { this.MessageEncoding = WSMessageEncoding.Text; TextMessageEncodingBindingElement element = (TextMessageEncodingBindingElement)encoding; this.TextEncoding = element.WriteEncoding; this.ReaderQuotas = element.ReaderQuotas; } else if (encoding is MtomMessageEncodingBindingElement) { this.messageEncoding = WSMessageEncoding.Mtom; MtomMessageEncodingBindingElement element2 = (MtomMessageEncodingBindingElement)encoding; this.TextEncoding = element2.WriteEncoding; this.ReaderQuotas = element2.ReaderQuotas; } this.TransactionFlow = txFlow.Transactions; this.reliableSession.Enabled = session != null; if (session != null) { this.session.InactivityTimeout = session.InactivityTimeout; this.session.Ordered = session.Ordered; } }
void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext context) { if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } bool everyoneAgrees = true; bool flag2 = true; TransactionFlowOption notAllowed = TransactionFlowOption.NotAllowed; TransactionProtocol transactionProtocol = TransactionFlowDefaults.TransactionProtocol; bool anOperationCares = false; bool flag4 = false; XmlElement item = null; XmlElement element2 = null; foreach (OperationDescription description in context.Contract.Operations) { ICollection <XmlElement> operationBindingAssertions = context.GetOperationBindingAssertions(description); foreach (XmlElement element3 in operationBindingAssertions) { if ((element3.NamespaceURI == "http://schemas.microsoft.com/ws/2006/02/tx/oletx") && (element3.LocalName == "OleTxAssertion")) { item = element3; TransactionFlowOption option = this.GetOption(element3, true); this.UpdateTransactionFlowAtribute(description, option); TrackAgreement(ref everyoneAgrees, option, ref notAllowed, ref anOperationCares); TrackAgreementTransactionProtocol(ref flag2, TransactionProtocol.OleTransactions, ref transactionProtocol, ref flag4); } else if ((element3.NamespaceURI == "http://schemas.xmlsoap.org/ws/2004/10/wsat") && (element3.LocalName == "ATAssertion")) { element2 = element3; TransactionFlowOption txFlow = this.GetOption(element3, true); this.UpdateTransactionFlowAtribute(description, txFlow); TrackAgreement(ref everyoneAgrees, txFlow, ref notAllowed, ref anOperationCares); TrackAgreementTransactionProtocol(ref flag2, TransactionProtocol.WSAtomicTransactionOctober2004, ref transactionProtocol, ref flag4); } else if ((element3.NamespaceURI == "http://docs.oasis-open.org/ws-tx/wsat/2006/06") && (element3.LocalName == "ATAssertion")) { element2 = element3; TransactionFlowOption option4 = this.GetOption(element3, false); this.UpdateTransactionFlowAtribute(description, option4); TrackAgreement(ref everyoneAgrees, option4, ref notAllowed, ref anOperationCares); TrackAgreementTransactionProtocol(ref flag2, TransactionProtocol.WSAtomicTransaction11, ref transactionProtocol, ref flag4); } } if (item != null) { operationBindingAssertions.Remove(item); } if (element2 != null) { operationBindingAssertions.Remove(element2); } } if (anOperationCares) { TransactionFlowBindingElement element4 = this.EnsureBindingElement(context); element4.Transactions = true; if (flag4 && flag2) { element4.TransactionProtocol = transactionProtocol; } else if (flag4) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(System.ServiceModel.SR.GetString("SFxCannotHaveDifferentTransactionProtocolsInOneBinding"))); } } }
private bool IsBindingElementsMatch(HttpTransportBindingElement transport, MessageEncodingBindingElement encoding, System.ServiceModel.Channels.TransactionFlowBindingElement txFlow, System.ServiceModel.Channels.ReliableSessionBindingElement session) { if (!this.GetTransport().IsMatch(transport)) { return(false); } if (this.MessageEncoding == WSMessageEncoding.Text) { if (!this.textEncoding.IsMatch(encoding)) { return(false); } } else if ((this.MessageEncoding == WSMessageEncoding.Mtom) && !this.mtomEncoding.IsMatch(encoding)) { return(false); } if (!this.txFlow.IsMatch(txFlow)) { return(false); } if (this.reliableSession.Enabled) { if (!this.session.IsMatch(session)) { return(false); } } else if (session != null) { return(false); } return(true); }
bool ImportNetTcpBinding( WsdlImporter importer, WsdlEndpointConversionContext context, CustomBinding custom, WS.Soap12Binding soap) { TcpTransportBindingElement transportElement = null; BinaryMessageEncodingBindingElement binaryElement = null; TransactionFlowBindingElement transactionFlowElement = null; WindowsStreamSecurityBindingElement windowsStreamElement = null; SslStreamSecurityBindingElement sslStreamElement = null; bool foundUnknownElement = false; foreach (var element in custom.Elements) { if (element is TcpTransportBindingElement) { transportElement = (TcpTransportBindingElement)element; } else if (element is BinaryMessageEncodingBindingElement) { binaryElement = (BinaryMessageEncodingBindingElement)element; } else if (element is TransactionFlowBindingElement) { transactionFlowElement = (TransactionFlowBindingElement)element; } else if (element is WindowsStreamSecurityBindingElement) { windowsStreamElement = (WindowsStreamSecurityBindingElement)element; } else if (element is SslStreamSecurityBindingElement) { sslStreamElement = (SslStreamSecurityBindingElement)element; } else { importer.AddWarning( "Found unknown binding element `{0}' while importing " + "binding `{1}'.", element.GetType(), custom.Name); foundUnknownElement = true; } } if (foundUnknownElement) { return(false); } if (transportElement == null) { importer.AddWarning( "Missing TcpTransportBindingElement while importing " + "binding `{0}'.", custom.Name); return(false); } if (binaryElement == null) { importer.AddWarning( "Missing BinaryMessageEncodingBindingElement while importing " + "binding `{0}'.", custom.Name); return(false); } if ((windowsStreamElement != null) && (sslStreamElement != null)) { importer.AddWarning( "Found both WindowsStreamSecurityBindingElement and " + "SslStreamSecurityBindingElement while importing binding `{0}.", custom.Name); return(false); } NetTcpSecurity security; if (windowsStreamElement != null) { security = new NetTcpSecurity(SecurityMode.Transport); security.Transport.ProtectionLevel = windowsStreamElement.ProtectionLevel; } else if (sslStreamElement != null) { security = new NetTcpSecurity(SecurityMode.TransportWithMessageCredential); } else { security = new NetTcpSecurity(SecurityMode.None); } var netTcp = new NetTcpBinding(transportElement, security, false); netTcp.Name = context.Endpoint.Binding.Name; netTcp.Namespace = context.Endpoint.Binding.Namespace; context.Endpoint.Binding = netTcp; return(true); }
internal static bool TryCreate(BindingElementCollection elements, out Binding binding) { binding = null; if (elements.Count > 6) { return(false); } PrivacyNoticeBindingElement privacy = null; System.ServiceModel.Channels.TransactionFlowBindingElement tfbe = null; System.ServiceModel.Channels.ReliableSessionBindingElement rsbe = null; SecurityBindingElement sbe = null; MessageEncodingBindingElement encoding = null; HttpTransportBindingElement transport = null; foreach (BindingElement element7 in elements) { if (element7 is SecurityBindingElement) { sbe = element7 as SecurityBindingElement; } else if (element7 is TransportBindingElement) { transport = element7 as HttpTransportBindingElement; } else if (element7 is MessageEncodingBindingElement) { encoding = element7 as MessageEncodingBindingElement; } else if (element7 is System.ServiceModel.Channels.TransactionFlowBindingElement) { tfbe = element7 as System.ServiceModel.Channels.TransactionFlowBindingElement; } else if (element7 is System.ServiceModel.Channels.ReliableSessionBindingElement) { rsbe = element7 as System.ServiceModel.Channels.ReliableSessionBindingElement; } else if (element7 is PrivacyNoticeBindingElement) { privacy = element7 as PrivacyNoticeBindingElement; } else { return(false); } } if (transport == null) { return(false); } if (encoding == null) { return(false); } if (((privacy != null) || !WSHttpBinding.TryCreate(sbe, transport, rsbe, tfbe, out binding)) && ((!WSFederationHttpBinding.TryCreate(sbe, transport, privacy, rsbe, tfbe, out binding) && !WS2007HttpBinding.TryCreate(sbe, transport, rsbe, tfbe, out binding)) && !WS2007FederationHttpBinding.TryCreate(sbe, transport, privacy, rsbe, tfbe, out binding))) { return(false); } if (tfbe == null) { tfbe = GetDefaultTransactionFlowBindingElement(); if ((binding is WS2007HttpBinding) || (binding is WS2007FederationHttpBinding)) { tfbe.TransactionProtocol = TransactionProtocol.WSAtomicTransaction11; } } WSHttpBindingBase base2 = binding as WSHttpBindingBase; base2.InitializeFrom(transport, encoding, tfbe, rsbe); if (!base2.IsBindingElementsMatch(transport, encoding, tfbe, rsbe)) { return(false); } return(true); }