本文整理匯總了C#中System.ServiceModel.Description.PolicyConversionContext類的典型用法代碼示例。如果您正苦於以下問題:C# PolicyConversionContext類的具體用法?C# PolicyConversionContext怎麽用?C# PolicyConversionContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PolicyConversionContext類屬於System.ServiceModel.Description命名空間,在下文中一共展示了PolicyConversionContext類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ImportPolicy
public void ImportPolicy(MetadataImporter importer,
PolicyConversionContext context)
{
Console.WriteLine("The custom policy importer has been called.");
foreach (XmlElement assertion in context.GetBindingAssertions())
{
Console.WriteLine(assertion.NamespaceURI + " : " + assertion.Name);
// locate a particular assertion by Name and NamespaceURI
XmlElement customAssertion = context.GetBindingAssertions().Find(name1, ns1);
if (customAssertion != null)
{
// Found assertion; remove from collection.
context.GetBindingAssertions().Remove(customAssertion);
Console.WriteLine(
"Removed our custom assertion from the imported "
+ "assertions collection and inserting our custom binding element."
);
// Here if you find the custom policy assertion that you are looking for,
// add the custom binding element that handles the functionality that the policy indicates.
// Attach it to the PolicyConversionContext.BindingElements collection.
// For example, if the custom policy had a "speed" attribute value:
/*
string speed
= customAssertion.GetAttribute(SpeedBindingElement.name2, SpeedBindingElement.ns2);
SpeedBindingElement e = new SpeedBindingElement(speed);
context.BindingElements.Add(e);
*/
}
// write assertion name in red.
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(assertion.NamespaceURI + " : " + assertion.Name);
//write contents in gray.
Console.WriteLine(assertion.OuterXml);
Console.ForegroundColor = ConsoleColor.Gray;
}
}
示例2: ExportPolicy
public class MyBindingElement : BindingElement, IPolicyExportExtension
{
// BindingElement implementation . . .
public void ExportPolicy(
MetadataExporter exporter, PolicyConversionContext context)
{
XmlDocument xmlDoc = new XmlDocument();
XmlElement xmlElement =
xmlDoc.CreateElement("MyPolicyAssertion");
context.GetBindingAssertions().Add(xmlElement);
}
// Note: All custom binding elements must return a deep clone
// to enable the run time to support multiple bindings using the
// same custom binding.
public override BindingElement Clone()
{
// this is just a placeholder
return null;
}
// Call the inner property.
public override T GetProperty<T>(BindingContext context)
{
return context.GetInnerProperty<T>();
}
}
public class Program {
public static void Main(string[] args) {
EndpointAddress address =
new EndpointAddress("http://localhost/metadata");
CustomBinding customBinding =
new CustomBinding(new BasicHttpBinding());
customBinding.Elements.Add(new MyBindingElement());
ContractDescription contract =
ContractDescription.GetContract(typeof(MyContract));
ServiceEndpoint endpoint =
new ServiceEndpoint(contract, customBinding, address);
MetadataExporter exporter = new WsdlExporter();
exporter.ExportEndpoint(endpoint);
}
}