WsdlContractConversionContext Class
Passed to custom WSDL exporters and importers to enable customization of the metadata export and import processes for a contract.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
The WsdlContractConversionContext type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | Contract | Gets the System.ServiceModel.Description::ContractDescription being exported or imported. |
![]() | WsdlPortType | Gets the System.Web.Services.Description::PortType that represents the contract. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetFaultDescription | Returns the fault description for the specified fault. |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetMessageDescription | Returns the message description for the specified message. |
![]() | GetOperation | Returns the operation for the specified operation description. |
![]() | GetOperationDescription | Returns the operation description associated with the operation. |
![]() | GetOperationFault | Returns the System.Web.Services.Description::OperationFault for the requested System.ServiceModel.Description::FaultDescription. |
![]() | GetOperationMessage | Gets a OperationMessage object for the specified message that represents a message type passed by the action of an XML Web service. |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
Use the WsdlContractConversionContext object to examine and modify items that are to be converted to or from WSDL.
When exporting metadata a WsdlContractConversionContext object is passed to the ExportContract and ExportEndpoint methods. Use the various methods and properties to obtain metadata objects that you can use to examine and modify to alter the published WSDL.
When importing metadata a WsdlContractConversionContext object is passed to the ImportContract and ImportEndpoint methods. Use the various methods and properties to obtain metadata objects that you can use to examine and modify the imported metadata.
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);
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 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.
