Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 ExportContract Method
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
IWsdlExportExtension..::.ExportContract Method

Writes custom Web Services Description Language (WSDL) elements into the generated WSDL for a contract.

Namespace:  System.ServiceModel.Description
Assembly:  System.ServiceModel (in System.ServiceModel.dll)
Visual Basic (Declaration)
Sub ExportContract ( _
    exporter As WsdlExporter, _
    context As WsdlContractConversionContext _
)
Visual Basic (Usage)
Dim instance As IWsdlExportExtension
Dim exporter As WsdlExporter
Dim context As WsdlContractConversionContext

instance.ExportContract(exporter, context)
C#
void ExportContract(
    WsdlExporter exporter,
    WsdlContractConversionContext context
)
Visual C++
void ExportContract(
    WsdlExporter^ exporter, 
    WsdlContractConversionContext^ context
)
JScript
function ExportContract(
    exporter : WsdlExporter, 
    context : WsdlContractConversionContext
)

Parameters

exporter
Type: System.ServiceModel.Description..::.WsdlExporter
The WsdlExporter that exports the contract information.
context
Type: System.ServiceModel.Description..::.WsdlContractConversionContext
Provides mappings from exported WSDL elements to the contract description.

The ExportContract method is called when the metadata export system is exporting the contract. Only contract and operation behaviors implementing IWsdlExportExtension get the ExportContract call. All behaviors implementing IWsdlExportExtension get the ExportEndpoint call.

Use the context parameter to modify the WSDL to be exported. For an example, see the Example section.

The following code example shows an IWsdlExportExtension that adds custom documentation attributes to the WSDL file as WSDL annotations.

C#
    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);
              }
            }
          }
        }
      }

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker