This documentation is archived and is not being maintained.

ServiceContractAttribute.Name Property

Gets or sets the name for the <portType> element in Web Services Description Language (WSDL).

Namespace:  System.ServiceModel
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public string Name { get; set; }

Property Value

Type: System.String
The default value is the name of the class or interface to which the ServiceContractAttribute is applied.


The value is null.


The value is an empty string.

Use the Name and the Namespace properties to control the name and namespace of the <portType> element in WSDL.

The following code example shows how to use the Name and Namespace properties of the ServiceContractAttribute to set the corresponding values in WSDL.

using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.Text;

namespace Microsoft.WCF.Documentation
  public interface ISampleService{
    string SampleMethod(string msg);

  class SampleService : ISampleService
  #region ISampleService Members

  public string  SampleMethod(string msg)
 	  return "The service greets you: " + msg;


The following code example shows an client for the preceding service that imported WSDL using the Service Model Metadata Utility Tool (Svcutil.exe). This client uses a HelloWorldProxy client rather than a SampleServiceProxy client (as is the case with the sample in the Example section of 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();
      // Making calls.
      Console.WriteLine("Enter the greeting to send: ");
      string greeting = Console.ReadLine();
      Console.WriteLine("The service responded: " + wcfClient.SampleMethod(greeting));

      // Done with service. 
    catch (TimeoutException timeProblem)
      Console.WriteLine("The service operation timed out. " + timeProblem.Message);
    catch (CommunicationException commProblem)
      Console.WriteLine("There was a communication problem. " + commProblem.Message);
      Console.WriteLine("Press ENTER to exit:");

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.