Share via


WsdlContractConversionContext.GetOperation(OperationDescription) Metodo

Definizione

Restituisce l'operazione per la descrizione dell'operazione specificata.

public:
 System::Web::Services::Description::Operation ^ GetOperation(System::ServiceModel::Description::OperationDescription ^ operation);
public System.Web.Services.Description.Operation GetOperation (System.ServiceModel.Description.OperationDescription operation);
member this.GetOperation : System.ServiceModel.Description.OperationDescription -> System.Web.Services.Description.Operation
Public Function GetOperation (operation As OperationDescription) As Operation

Parametri

operation
OperationDescription

Oggetto della classe OperationDescription relativo all'oggetto della classe Operation richiesto.

Restituisce

L'operazione per la descrizione dell'operazione specificata.

Eccezioni

Valore non trovato.

Il valore è null.

Esempio

Nell'esempio di codice seguente viene illustrato l'utilizzo della classe WsdlContractConversionContext per aggiungere annotazioni WSDL personalizzate ai metadati esportati utilizzando le proprietà WsdlPortType e Contract. Durante l'esportazione di operazioni, il metodo scorre le descrizioni dell'operazione e individuare l'oggetto della classe System.Web.Services.Description.Operation associata chiamando il metodo GetOperation.

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

Si applica a