IWsdlExportExtension Interface
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Defines endpoint or contract behaviors that can export custom metadata.
public interface class IWsdlExportExtension
public interface IWsdlExportExtension
type IWsdlExportExtension = interface
Public Interface IWsdlExportExtension
- Derived
The following code example shows an IWsdlExportExtension that adds custom documentation attributes to the WSDL file as WSDL annotations.
public void ExportContract(WsdlExporter exporter, WsdlContractConversionContext context)
{
Console.WriteLine("Inside ExportContract");
if (context.Contract != null)
{
// Inside this block it is the contract-level comment attribute.
// This.Text returns the string for the contract attribute.
// Set the doc element; if this isn't done first, there is no XmlElement in the
// DocumentElement property.
context.WsdlPortType.Documentation = string.Empty;
// Contract comments.
XmlDocument owner = context.WsdlPortType.DocumentationElement.OwnerDocument;
XmlElement summaryElement = Formatter.CreateSummaryElement(owner, this.Text);
context.WsdlPortType.DocumentationElement.AppendChild(summaryElement);
foreach (OperationDescription op in context.Contract.Operations)
{
Operation operation = context.GetOperation(op);
object[] opAttrs = op.SyncMethod.GetCustomAttributes(typeof(WsdlDocumentationAttribute), false);
if (opAttrs.Length == 1)
{
string opComment = ((WsdlDocumentationAttribute)opAttrs[0]).Text;
// This.Text returns the string for the operation-level attributes.
// Set the doc element; if this isn't done first, there is no XmlElement in the
// DocumentElement property.
operation.Documentation = String.Empty;
// Operation C# triple comments.
XmlDocument opOwner = operation.DocumentationElement.OwnerDocument;
XmlElement newSummaryElement = Formatter.CreateSummaryElement(opOwner, opComment);
operation.DocumentationElement.AppendChild(newSummaryElement);
// Get returns information
ParameterInfo returnValue = op.SyncMethod.ReturnParameter;
object[] returnAttrs = returnValue.GetCustomAttributes(typeof(WsdlParameterDocumentationAttribute), false);
if (returnAttrs.Length == 1)
{
// <returns>text.</returns>
XmlElement returnsElement =
Formatter.CreateReturnsElement(
opOwner,
((WsdlParameterDocumentationAttribute)returnAttrs[0]).ParamComment
);
operation.DocumentationElement.AppendChild(returnsElement);
}
// Get parameter information.
ParameterInfo[] args = op.SyncMethod.GetParameters();
for (int i = 0; i < args.Length; i++)
{
object[] docAttrs
= args[i].GetCustomAttributes(typeof(WsdlParameterDocumentationAttribute), false);
if (docAttrs.Length != 0)
{
// <param name="Int1">Text.</param>
XmlElement newParamElement = opOwner.CreateElement("param");
XmlAttribute paramName = opOwner.CreateAttribute("name");
paramName.Value = args[i].Name;
newParamElement.InnerText
= ((WsdlParameterDocumentationAttribute)docAttrs[0]).ParamComment;
newParamElement.Attributes.Append(paramName);
operation.DocumentationElement.AppendChild(newParamElement);
}
}
}
}
}
To modify and extend the Web Services Description Language (WSDL) exported by WsdlExporter objects, implement the IWsdlExportExtension interface on an endpoint, contract, or operation behavior (an object that implements either IContractBehavior, IEndpointBehavior, or IOperationBehavior) and add the behavior to the Behaviors, Behaviors, or Behaviors property. In addition, you can also implement IWsdlExportExtension on a BindingElement.
Note
IWsdlExportExtension implementations are never invoked if they are implemented as an IServiceBehavior.
IWsdlExportExtension does not export custom policy assertions even though Windows Communication Foundation (WCF) exports custom binding policy assertions to the appropriate element inside WSDL. If you want to export custom policy assertions, implement the IPolicyExportExtension interface.
The metadata publication process begins by calling WsdlExporter.ExportEndpoints which in turn calls WsdlExporter.ExportEndpoint for each endpoint.
The endpoint is exported by first exporting its contract.When exporting a contract the System.ServiceModel.Description.WsdlExporter calls the IWsdlExportExtension.ExportContract method on all IWsdlExportExtension implementations on the contract, and operation behaviors for that contract. Operations that use wildcard actions are not exported in metadata, so IWsdlExportExtension implementations on operation behaviors for these operations are not exported.
After exporting the contract, the port and binding are exported and exported policy expressions are attached.
Both the ExportContract and the ExportEndpoint methods provide access to the WsdlExporter so that IWsdlExportExtension implementations can report recoverable errors and warnings through the Errors property. The context objects passed into both methods provide convenient mappings from exported WSDL elements to properties of ContractDescription and ServiceEndpoint objects.
If an IWsdlExportExtension implementation throws an exception on export, the generated metadata is in an inconsistent state and the WsdlExporter object should be discarded.
Note
Custom export extension must run after the built-in serializer populates the service description.
Export |
Writes custom Web Services Description Language (WSDL) elements into the generated WSDL for a contract. |
Export |
Writes custom Web Services Description Language (WSDL) elements into the generated WSDL for an endpoint. |
Product | Versions |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: