ServiceContractAttribute.Name Eigenschap
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee haalt u de naam op voor het <portType> element in WSDL (Web Services Description Language).
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
Waarde van eigenschap
De standaardwaarde is de naam van de klasse of interface waarop de ServiceContractAttribute klasse of interface is toegepast.
Uitzonderingen
De waarde is null.
De waarde is een lege tekenreeks.
Voorbeelden
In het volgende codevoorbeeld ziet u hoe u de Name en Namespace eigenschappen van de ServiceContractAttribute code gebruikt om de bijbehorende waarden in WSDL in te stellen.
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
}
}
In het volgende codevoorbeeld ziet u een WCF-client (Windows Communication Foundation) voor de voorgaande service die WSDL heeft geïmporteerd met behulp van het hulpprogramma ServiceModel Metadata Utility (Svcutil.exe). Deze client maakt gebruik van een HelloWorldProxy client in plaats van een SampleServiceProxy client (zoals het geval is met het voorbeeld in de sectie Voorbeeld van 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();
}
}
}
Opmerkingen
Gebruik de Name en de Namespace eigenschappen om de naam en naamruimte van het <portType> element in WSDL te beheren.