WsdlContractConversionContext 類別

定義

傳遞至自訂 WSDL 匯出工具和匯入工具,以啟用合約的中繼資料匯出和匯入處理的自訂。

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

範例

下列程式碼範例會示範如何使用 WsdlContractConversionContext,利用 WsdlPortTypeContract 屬性將自訂 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 的項目。

當匯出中繼資料時,會將 WsdlContractConversionContext 物件傳遞至 ExportContractExportEndpoint 方法。 您可以使用各種不同的方法和屬性,以取得可以用來檢查和修改的中繼資料物件,進而變更已發行的 WSDL。

當匯入中繼資料時,會將 WsdlContractConversionContext 物件傳遞至 ImportContractImportEndpoint 方法。 您可以使用各種不同的方法和屬性,以取得可以用來檢查和修改匯入之中繼資料的中繼資料物件。

屬性

Contract

取得正在匯出或匯入的 ContractDescription

WsdlPortType

取得表示合約的 PortType

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetFaultDescription(OperationFault)

傳回指定錯誤的錯誤描述。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetMessageDescription(OperationMessage)

傳回指定訊息的訊息描述。

GetOperation(OperationDescription)

傳回指定作業描述的作業。

GetOperationDescription(Operation)

傳回與作業關聯的作業描述。

GetOperationFault(FaultDescription)

傳回要求之 OperationFaultFaultDescription

GetOperationMessage(MessageDescription)

取得指定之 OperationMessagemessage 物件,表示由 XML Web 服務的動作所傳遞的訊息型別。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於