Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

ServiceDescription.GetService Method (Object)

Returns a service description initialized with a specified service object.

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

public static ServiceDescription GetService(
	Object serviceImplementation
)

Parameters

serviceImplementation
Type: System.Object
The Object that implements the service.

Return Value

Type: System.ServiceModel.Description.ServiceDescription
The ServiceDescription for the service object provided.

ExceptionCondition
ArgumentNullException

serviceImplementation is null.

Use this method to reflect on behaviors using the programming model when replacing ServiceHostBase with you own hosting mechanism.

GetService(Object) initializes the Name, Namespace, and ConfigurationName properties, and ensures that the ServiceBehaviorAttribute is attached to the service and adds any relevant service behaviors to Behaviors.

The following sample shows how to iterate through the service behaviors contained in the service description.


			' Instantiate a service description specifying a service object
			' Note: Endpoints collection and other properties will be null since 
			' we have not specified them
			Dim svcObj As New CalculatorService()
			Dim sd3 As ServiceDescription = ServiceDescription.GetService(svcObj)
            Dim serviceName = sd3.Name
			Console.WriteLine("Service name: {0}", serviceName)



// Instantiate a service description specifying a service object
// Note: Endpoints collection and other properties will be null since 
// we have not specified them
CalculatorService svcObj = new CalculatorService();
ServiceDescription sd3 = ServiceDescription.GetService(svcObj);
String serviceName = sd3.Name;
Console.WriteLine("Service name: {0}", serviceName);



ServiceDescription d = ServiceDescription.GetService(typeof(CalculatorService));
foreach (IServiceBehavior isb in d.Behaviors)
{
    Console.WriteLine(isb.GetType());
}
Console.WriteLine();


.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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.

Community Additions

ADD
Show:
© 2015 Microsoft