本文整理汇总了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;
}
}
开发者ID:.NET开发者,项目名称:System.ServiceModel.Description,代码行数:38,代码来源:PolicyConversionContext
示例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);
}
}
开发者ID:.NET开发者,项目名称:System.ServiceModel.Description,代码行数:44,代码来源:PolicyConversionContext
注:本文中的System.ServiceModel.Description.PolicyConversionContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论