ServiceContractAttribute.Name Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene o imposta il nome dell'elemento <portType> in Web Services Description Language (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
Valore della proprietà
Il valore predefinito è il nome della classe o dell'interfaccia a cui viene applicato l'oggetto ServiceContractAttribute .
Eccezioni
Il valore è Null.
Il valore è una stringa vuota.
Esempio
Nell'esempio di codice seguente viene illustrato come utilizzare le Name proprietà e Namespace di ServiceContractAttribute per impostare i valori corrispondenti in 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
}
}
Nell'esempio di codice seguente viene illustrato un client Windows Communication Foundation (WCF) per il servizio precedente che ha importato WSDL usando lo strumento utilità metadati ServiceModel (Svcutil.exe). Questo client usa un HelloWorldProxy client anziché un SampleServiceProxy client ( come nel caso dell'esempio nella sezione Esempio di 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();
}
}
}
Commenti
Utilizzare le Name proprietà e Namespace per controllare il nome e lo spazio dei nomi dell'elemento <portType> in WSDL.