语言

WsdlContractConversionContext 类

定义

传递给自定义 WSDL 导出程序和导入程序,以便自定义协定的元数据导出和导入过程。

public ref class WsdlContractConversionContext
public class WsdlContractConversionContext
type WsdlContractConversionContext = class
Public Class WsdlContractConversionContext
继承
WsdlContractConversionContext

示例

下面的代码示例演示如何使用 WsdlContractConversionContextWsdlPortTypeContract 和属性将自定义 WSDL 批注添加到导出的元数据。

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

注解

使用 WsdlContractConversionContext 对象检查和修改要转换为 WSDL 或从 WSDL 转换的项。

导出元数据时,对象 WsdlContractConversionContext 将 ExportContract 传递给和 ExportEndpoint 方法。 使用各种方法和属性来获取元数据对象,可以使用这些对象来检查和修改已发布的 WSDL。

导入元数据时,对象 WsdlContractConversionContext 将 ImportContract 传递给和 ImportEndpoint 方法。 使用各种方法和属性获取可用于检查和修改导入的元数据的元数据对象。

属性

名称 说明
Contract

ContractDescription获取正在导出或导入的。

WsdlPortType

获取表示协定的项 PortType 。

方法

名称 说明
Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
GetFaultDescription(OperationFault)

返回指定错误的错误说明。

GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetMessageDescription(OperationMessage)

返回指定消息的消息说明。

GetOperation(OperationDescription)

返回指定操作说明的操作。

GetOperationDescription(Operation)

返回与操作关联的操作说明。

GetOperationFault(FaultDescription)

返回 OperationFault 所请求 FaultDescription的 。

GetOperationMessage(MessageDescription)

获取一个 OperationMessage 对象, message 该对象表示由 XML Web 服务的操作传递的消息类型。

GetType()

获取当前实例的 Type。

(继承自 Object)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
ToString()

返回一个表示当前对象的字符串。

(继承自 Object)

适用于