本文整理汇总了C#中System.ServiceModel.Description.PolicyConversionContext.GetOperationBindingAssertions方法的典型用法代码示例。如果您正苦于以下问题:C# PolicyConversionContext.GetOperationBindingAssertions方法的具体用法?C# PolicyConversionContext.GetOperationBindingAssertions怎么用?C# PolicyConversionContext.GetOperationBindingAssertions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ServiceModel.Description.PolicyConversionContext
的用法示例。
在下文中一共展示了PolicyConversionContext.GetOperationBindingAssertions方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportOperationScopeSupportingTokensPolicy
void ImportOperationScopeSupportingTokensPolicy(MetadataImporter importer, PolicyConversionContext policyContext, SecurityBindingElement binding)
{
foreach (OperationDescription operation in policyContext.Contract.Operations)
{
string requestAction = null;
foreach (MessageDescription message in operation.Messages)
{
if (message.Direction == MessageDirection.Input)
{
requestAction = message.Action;
break;
}
}
SupportingTokenParameters requirements = new SupportingTokenParameters();
SupportingTokenParameters optionalRequirements = new SupportingTokenParameters();
ICollection<XmlElement> operationBindingAssertions = policyContext.GetOperationBindingAssertions(operation);
this.ImportSupportingTokenAssertions(importer, policyContext, operationBindingAssertions, requirements, optionalRequirements);
if (requirements.Endorsing.Count > 0
|| requirements.Signed.Count > 0
|| requirements.SignedEncrypted.Count > 0
|| requirements.SignedEndorsing.Count > 0)
{
if (requestAction != null)
{
binding.OperationSupportingTokenParameters[requestAction] = requirements;
}
else
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.CannotImportSupportingTokensForOperationWithoutRequestAction)));
}
}
if (optionalRequirements.Endorsing.Count > 0
|| optionalRequirements.Signed.Count > 0
|| optionalRequirements.SignedEncrypted.Count > 0
|| optionalRequirements.SignedEndorsing.Count > 0)
{
if (requestAction != null)
{
binding.OptionalOperationSupportingTokenParameters[requestAction] = optionalRequirements;
}
else
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.CannotImportSupportingTokensForOperationWithoutRequestAction)));
}
}
}
}
示例2: foreach
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)));
}
}
示例3: ImportMessageScopeProtectionPolicy
void ImportMessageScopeProtectionPolicy(MetadataImporter importer, PolicyConversionContext policyContext)
{
MessagePartSpecification endpointSignedParts;
MessagePartSpecification endpointEncryptedParts;
bool isContractAssociatedWithAtLeastOneOtherBinding;
ContractProtectionLevel otherBindingProtectionLevel = null;
bool hasContractProtectionLevel = false;
bool isContractProtectionLevelUniform = true;
ProtectionLevel contractProtectionLevel = ProtectionLevel.None;
string contractAssociationName = String.Format("{0}:{1}:{2}", ContractProtectionLevelKey, policyContext.Contract.Name, policyContext.Contract.Namespace);
if (importer.State.ContainsKey(contractAssociationName))
{
isContractAssociatedWithAtLeastOneOtherBinding = true;
otherBindingProtectionLevel = (ContractProtectionLevel)importer.State[contractAssociationName];
}
else
{
isContractAssociatedWithAtLeastOneOtherBinding = false;
}
ICollection<XmlElement> endpointBindingAssertions = policyContext.GetBindingAssertions();
this.ImportProtectionAssertions(endpointBindingAssertions, out endpointSignedParts, out endpointEncryptedParts);
if (importer.State.ContainsKey(InSecureConversationBootstrapBindingImportMode))
{
// when importing secure conversation boostrap binding, add the endpoint scope protection requirements
// to the importer state to be consumed in SecurityPolicy11.TryImportWsspBootrstapPolicyAssertion
if (endpointEncryptedParts != null)
importer.State[SecureConversationBootstrapEncryptionRequirements] = endpointEncryptedParts;
if (endpointSignedParts != null)
importer.State[SecureConversationBootstrapSignatureRequirements] = endpointSignedParts;
}
foreach (OperationDescription operation in policyContext.Contract.Operations)
{
MessagePartSpecification operationSignedParts;
MessagePartSpecification operationEncryptedParts;
ICollection<XmlElement> operationBindingAssertions = policyContext.GetOperationBindingAssertions(operation);
this.ImportProtectionAssertions(operationBindingAssertions, out operationSignedParts, out operationEncryptedParts);
this.AddParts(ref operationSignedParts, endpointSignedParts);
this.AddParts(ref operationEncryptedParts, endpointEncryptedParts);
MessagePartSpecification messageSignedParts;
MessagePartSpecification messageEncryptedParts;
bool hasProtectionLevel = false;
bool isProtectionLevelUniform = true;
ProtectionLevel protectionLevel = ProtectionLevel.None;
// import application message protection requirements
foreach (MessageDescription message in operation.Messages)
{
ICollection<XmlElement> messageBindingAssertions = policyContext.GetMessageBindingAssertions(message);
this.ImportProtectionAssertions(messageBindingAssertions, out messageSignedParts, out messageEncryptedParts);
this.AddParts(ref messageSignedParts, operationSignedParts);
this.AddParts(ref messageEncryptedParts, operationEncryptedParts);
// validate or set body protection level
ProtectionLevel newProtectionLevel = GetProtectionLevel(messageSignedParts.IsBodyIncluded, messageEncryptedParts.IsBodyIncluded, message.Action);
if (OperationFormatter.IsValidReturnValue(message.Body.ReturnValue))
{
ValidateExistingOrSetNewProtectionLevel(message.Body.ReturnValue, message, operation, policyContext.Contract, newProtectionLevel);
}
foreach (MessagePartDescription body in message.Body.Parts)
{
ValidateExistingOrSetNewProtectionLevel(body, message, operation, policyContext.Contract, newProtectionLevel);
}
if (!OperationFormatter.IsValidReturnValue(message.Body.ReturnValue) || message.Body.Parts.Count == 0)
{
ValidateExistingOrSetNewProtectionLevel(null, message, operation, policyContext.Contract, newProtectionLevel);
}
if (hasProtectionLevel)
{
if (protectionLevel != newProtectionLevel)
{
isProtectionLevelUniform = false;
}
}
else
{
protectionLevel = newProtectionLevel;
hasProtectionLevel = true;
}
if (hasContractProtectionLevel)
{
if (contractProtectionLevel != newProtectionLevel)
{
isContractProtectionLevelUniform = false;
}
}
else
{
contractProtectionLevel = newProtectionLevel;
hasContractProtectionLevel = true;
}
// validate o set header protection level
foreach (MessageHeaderDescription header in message.Headers)
//.........这里部分代码省略.........
示例4: AttachPolicy
internal void AttachPolicy(ServiceEndpoint endpoint, WsdlEndpointConversionContext endpointContext, PolicyConversionContext policyContext)
{
SortedList<string, string> policyKeys = new SortedList<string, string>();
NamingHelper.DoesNameExist policyKeyIsUnique
= delegate(string name, object nameCollection)
{
return policyKeys.ContainsKey(name);
};
string key, keyBase;
ICollection<XmlElement> assertions;
WsdlNS.ServiceDescription policyWsdl = endpointContext.WsdlBinding.ServiceDescription;
assertions = policyContext.GetBindingAssertions();
// Add [wsdl:Binding] level Policy
WsdlNS.Binding wsdlBinding = endpointContext.WsdlBinding;
if (assertions.Count > 0)
{
keyBase = CreateBindingPolicyKey(wsdlBinding);
key = NamingHelper.GetUniqueName(keyBase, policyKeyIsUnique, null);
policyKeys.Add(key, key);
AttachItemPolicy(assertions, key, policyWsdl, wsdlBinding);
}
foreach (OperationDescription operation in endpoint.Contract.Operations)
{
if (!WsdlExporter.OperationIsExportable(operation))
{
continue;
}
assertions = policyContext.GetOperationBindingAssertions(operation);
// Add [wsdl:Binding/wsdl:operation] policy
if (assertions.Count > 0)
{
WsdlNS.OperationBinding wsdlOperationBinding = endpointContext.GetOperationBinding(operation);
keyBase = CreateOperationBindingPolicyKey(wsdlOperationBinding);
key = NamingHelper.GetUniqueName(keyBase, policyKeyIsUnique, null);
policyKeys.Add(key, key);
AttachItemPolicy(assertions, key, policyWsdl, wsdlOperationBinding);
}
//
// Add [wsdl:Binding/wsdl:operation] child policy
//
foreach (MessageDescription message in operation.Messages)
{
assertions = policyContext.GetMessageBindingAssertions(message);
// Add [wsdl:Binding/wsdl:operation/wsdl:(input, output, message)] policy
if (assertions.Count > 0)
{
WsdlNS.MessageBinding wsdlMessageBinding = endpointContext.GetMessageBinding(message);
keyBase = CreateMessageBindingPolicyKey(wsdlMessageBinding, message.Direction);
key = NamingHelper.GetUniqueName(keyBase, policyKeyIsUnique, null);
policyKeys.Add(key, key);
AttachItemPolicy(assertions, key, policyWsdl, wsdlMessageBinding);
}
}
foreach (FaultDescription fault in operation.Faults)
{
assertions = policyContext.GetFaultBindingAssertions(fault);
// Add [wsdl:Binding/wsdl:operation/wsdl:fault] policy
if (assertions.Count > 0)
{
WsdlNS.FaultBinding wsdlFaultBinding = endpointContext.GetFaultBinding(fault);
keyBase = CreateFaultBindingPolicyKey(wsdlFaultBinding);
key = NamingHelper.GetUniqueName(keyBase, policyKeyIsUnique, null);
policyKeys.Add(key, key);
AttachItemPolicy(assertions, key, policyWsdl, wsdlFaultBinding);
}
}
}
}
示例5: TryImportPolicy
internal bool TryImportPolicy(PolicyConversionContext policyContext)
{
foreach (IPolicyImportExtension policyImporter in policyExtensions)
try
{
policyImporter.ImportPolicy(this, policyContext);
}
#pragma warning suppress 56500 // covered by FxCOP
catch (Exception e)
{
if (Fx.IsFatal(e))
throw;
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateExtensionException(policyImporter, e));
}
if (policyContext.GetBindingAssertions().Count != 0)
return false;
foreach (OperationDescription operation in policyContext.Contract.Operations)
{
if (policyContext.GetOperationBindingAssertions(operation).Count != 0)
return false;
foreach (MessageDescription message in operation.Messages)
if (policyContext.GetMessageBindingAssertions(message).Count != 0)
return false;
}
return true;
}
示例6: AttachPolicy
internal void AttachPolicy(ServiceEndpoint endpoint, WsdlEndpointConversionContext endpointContext, PolicyConversionContext policyContext)
{
string str;
SortedList<string, string> policyKeys = new SortedList<string, string>();
NamingHelper.DoesNameExist doesNameExist = (name, nameCollection) => policyKeys.ContainsKey(name);
System.Web.Services.Description.ServiceDescription serviceDescription = endpointContext.WsdlBinding.ServiceDescription;
ICollection<XmlElement> bindingAssertions = policyContext.GetBindingAssertions();
System.Web.Services.Description.Binding wsdlBinding = endpointContext.WsdlBinding;
if (bindingAssertions.Count > 0)
{
str = NamingHelper.GetUniqueName(CreateBindingPolicyKey(wsdlBinding), doesNameExist, null);
policyKeys.Add(str, str);
this.AttachItemPolicy(bindingAssertions, str, serviceDescription, wsdlBinding);
}
foreach (OperationDescription description2 in endpoint.Contract.Operations)
{
if (WsdlExporter.OperationIsExportable(description2))
{
bindingAssertions = policyContext.GetOperationBindingAssertions(description2);
if (bindingAssertions.Count > 0)
{
OperationBinding operationBinding = endpointContext.GetOperationBinding(description2);
str = NamingHelper.GetUniqueName(CreateOperationBindingPolicyKey(operationBinding), doesNameExist, null);
policyKeys.Add(str, str);
this.AttachItemPolicy(bindingAssertions, str, serviceDescription, operationBinding);
}
foreach (MessageDescription description3 in description2.Messages)
{
bindingAssertions = policyContext.GetMessageBindingAssertions(description3);
if (bindingAssertions.Count > 0)
{
MessageBinding messageBinding = endpointContext.GetMessageBinding(description3);
str = NamingHelper.GetUniqueName(CreateMessageBindingPolicyKey(messageBinding, description3.Direction), doesNameExist, null);
policyKeys.Add(str, str);
this.AttachItemPolicy(bindingAssertions, str, serviceDescription, messageBinding);
}
}
foreach (FaultDescription description4 in description2.Faults)
{
bindingAssertions = policyContext.GetFaultBindingAssertions(description4);
if (bindingAssertions.Count > 0)
{
FaultBinding faultBinding = endpointContext.GetFaultBinding(description4);
str = NamingHelper.GetUniqueName(CreateFaultBindingPolicyKey(faultBinding), doesNameExist, null);
policyKeys.Add(str, str);
this.AttachItemPolicy(bindingAssertions, str, serviceDescription, faultBinding);
}
}
}
}
}
示例7: ImportOperationScopeSupportingTokensPolicy
private void ImportOperationScopeSupportingTokensPolicy(MetadataImporter importer, PolicyConversionContext policyContext, SecurityBindingElement binding)
{
foreach (OperationDescription description in policyContext.Contract.Operations)
{
string action = null;
foreach (MessageDescription description2 in description.Messages)
{
if (description2.Direction == MessageDirection.Input)
{
action = description2.Action;
break;
}
}
SupportingTokenParameters requirements = new SupportingTokenParameters();
SupportingTokenParameters optionalRequirements = new SupportingTokenParameters();
ICollection<XmlElement> operationBindingAssertions = policyContext.GetOperationBindingAssertions(description);
this.ImportSupportingTokenAssertions(importer, policyContext, operationBindingAssertions, requirements, optionalRequirements);
if (((requirements.Endorsing.Count > 0) || (requirements.Signed.Count > 0)) || ((requirements.SignedEncrypted.Count > 0) || (requirements.SignedEndorsing.Count > 0)))
{
if (action == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("CannotImportSupportingTokensForOperationWithoutRequestAction")));
}
binding.OperationSupportingTokenParameters[action] = requirements;
}
if (((optionalRequirements.Endorsing.Count > 0) || (optionalRequirements.Signed.Count > 0)) || ((optionalRequirements.SignedEncrypted.Count > 0) || (optionalRequirements.SignedEndorsing.Count > 0)))
{
if (action == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("CannotImportSupportingTokensForOperationWithoutRequestAction")));
}
binding.OptionalOperationSupportingTokenParameters[action] = optionalRequirements;
}
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:35,代码来源:SecurityBindingElementImporter.cs
示例8: ImportMessageScopeProtectionPolicy
private void ImportMessageScopeProtectionPolicy(MetadataImporter importer, PolicyConversionContext policyContext)
{
MessagePartSpecification specification;
MessagePartSpecification specification2;
bool flag;
ContractProtectionLevel level = null;
bool hasProtectionRequirements = false;
bool hasUniformProtectionLevel = true;
ProtectionLevel none = ProtectionLevel.None;
string key = string.Format("{0}:{1}:{2}", "ContractProtectionLevelKey", policyContext.Contract.Name, policyContext.Contract.Namespace);
if (importer.State.ContainsKey(key))
{
flag = true;
level = (ContractProtectionLevel) importer.State[key];
}
else
{
flag = false;
}
ICollection<XmlElement> bindingAssertions = policyContext.GetBindingAssertions();
this.ImportProtectionAssertions(bindingAssertions, out specification, out specification2);
if (importer.State.ContainsKey("InSecureConversationBootstrapBindingImportMode"))
{
if (specification2 != null)
{
importer.State["SecureConversationBootstrapEncryptionRequirements"] = specification2;
}
if (specification != null)
{
importer.State["SecureConversationBootstrapSignatureRequirements"] = specification;
}
}
foreach (OperationDescription description in policyContext.Contract.Operations)
{
MessagePartSpecification specification3;
MessagePartSpecification specification4;
MessagePartSpecification specification5;
MessagePartSpecification specification6;
ICollection<XmlElement> operationBindingAssertions = policyContext.GetOperationBindingAssertions(description);
this.ImportProtectionAssertions(operationBindingAssertions, out specification3, out specification4);
this.AddParts(ref specification3, specification);
this.AddParts(ref specification4, specification2);
bool flag4 = false;
bool flag5 = true;
ProtectionLevel level3 = ProtectionLevel.None;
foreach (MessageDescription description2 in description.Messages)
{
ICollection<XmlElement> messageBindingAssertions = policyContext.GetMessageBindingAssertions(description2);
this.ImportProtectionAssertions(messageBindingAssertions, out specification5, out specification6);
this.AddParts(ref specification5, specification3);
this.AddParts(ref specification6, specification4);
ProtectionLevel newProtectionLevel = GetProtectionLevel(specification5.IsBodyIncluded, specification6.IsBodyIncluded, description2.Action);
if (OperationFormatter.IsValidReturnValue(description2.Body.ReturnValue))
{
this.ValidateExistingOrSetNewProtectionLevel(description2.Body.ReturnValue, description2, description, policyContext.Contract, newProtectionLevel);
}
foreach (MessagePartDescription description3 in description2.Body.Parts)
{
this.ValidateExistingOrSetNewProtectionLevel(description3, description2, description, policyContext.Contract, newProtectionLevel);
}
if (!OperationFormatter.IsValidReturnValue(description2.Body.ReturnValue) || (description2.Body.Parts.Count == 0))
{
this.ValidateExistingOrSetNewProtectionLevel(null, description2, description, policyContext.Contract, newProtectionLevel);
}
if (flag4)
{
if (level3 != newProtectionLevel)
{
flag5 = false;
}
}
else
{
level3 = newProtectionLevel;
flag4 = true;
}
if (hasProtectionRequirements)
{
if (none != newProtectionLevel)
{
hasUniformProtectionLevel = false;
}
}
else
{
none = newProtectionLevel;
hasProtectionRequirements = true;
}
foreach (MessageHeaderDescription description4 in description2.Headers)
{
bool signed = specification5.IsHeaderIncluded(description4.Name, description4.Namespace);
bool encrypted = specification6.IsHeaderIncluded(description4.Name, description4.Namespace);
newProtectionLevel = GetProtectionLevel(signed, encrypted, description2.Action);
this.ValidateExistingOrSetNewProtectionLevel(description4, description2, description, policyContext.Contract, newProtectionLevel);
if (flag4)
{
if (level3 != newProtectionLevel)
{
flag5 = false;
}
//.........这里部分代码省略.........
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:SecurityBindingElementImporter.cs