This documentation is archived and is not being maintained.

WsdlContractConversionContext.WsdlPortType Property

Gets the System.Web.Services.Description.PortType that represents the contract.

Namespace:  System.ServiceModel.Description
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public PortType WsdlPortType { get; }

Property Value

Type: System.Web.Services.Description.PortType
The System.Web.Services.Description.PortType that represents the contract.

The following code example shows the use of the WsdlContractConversionContext to add custom WSDL annotations to the exported metadata using the WsdlPortType and Contract properties.

    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); 

        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);

            // Get returns information
            ParameterInfo returnValue = op.SyncMethod.ReturnParameter;
            object[] returnAttrs = returnValue.GetCustomAttributes(typeof(WsdlParameterDocumentationAttribute), false);
            if (returnAttrs.Length == 1)
              // <returns>text.</returns>
              XmlElement 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;
                  = ((WsdlParameterDocumentationAttribute)docAttrs[0]).ParamComment;

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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