ServiceContractAttribute.Name Propiedad
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Obtiene o establece el nombre del <portType> elemento en el lenguaje de descripción de servicios web (WSDL).
public:
property System::String ^ Name { System::String ^ get(); void set(System::String ^ value); };
public string Name { get; set; }
member this.Name : string with get, set
Public Property Name As String
Valor de propiedad
El valor predeterminado es el nombre de la clase o interfaz a la que se aplica .ServiceContractAttribute
Excepciones
El valor es NULL.
El valor es una cadena vacía.
Ejemplos
En el ejemplo de código siguiente se muestra cómo usar las Name propiedades y Namespace de ServiceContractAttribute para establecer los valores correspondientes en WSDL.
using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.Text;
namespace Microsoft.WCF.Documentation
{
[ServiceContract(
Name="HelloWorld",
Namespace="http://Microsoft.WCF.Documentation"
)]
public interface ISampleService{
[OperationContract]
string SampleMethod(string msg);
}
class SampleService : ISampleService
{
#region ISampleService Members
public string SampleMethod(string msg)
{
return "The service greets you: " + msg;
}
#endregion
}
}
En el ejemplo de código siguiente se muestra un cliente de Windows Communication Foundation (WCF) para el servicio anterior que importó WSDL mediante la Herramienta de utilidad de metadatos de ServiceModel (Svcutil.exe). Este cliente usa un HelloWorldProxy cliente en lugar de un SampleServiceProxy cliente (como sucede con el ejemplo en la sección Ejemplo de ServiceContractAttribute).
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
public class Client
{
public static void Main()
{
// Picks up configuration from the config file.
HelloWorldClient wcfClient = new HelloWorldClient();
try
{
// Making calls.
Console.WriteLine("Enter the greeting to send: ");
string greeting = Console.ReadLine();
Console.WriteLine("The service responded: " + wcfClient.SampleMethod(greeting));
// Done with service.
wcfClient.Close();
Console.WriteLine("Done!");
}
catch (TimeoutException timeProblem)
{
Console.WriteLine("The service operation timed out. " + timeProblem.Message);
wcfClient.Abort();
}
catch (CommunicationException commProblem)
{
Console.WriteLine("There was a communication problem. " + commProblem.Message);
wcfClient.Abort();
}
finally
{
Console.WriteLine("Press ENTER to exit:");
Console.ReadLine();
}
}
}
Comentarios
Use las Name propiedades y Namespace para controlar el nombre y el espacio de nombres del <portType> elemento en WSDL.