Upravit

Sdílet prostřednictvím


ServiceDescription.GetService Method

Definition

Returns a service description initialized with a specified service object or type.

Overloads

GetService(Object)

Returns a service description initialized with a specified service object.

GetService(Type)

Returns a service description initialized with a specified service type.

GetService(Object)

Returns a service description initialized with a specified service object.

public:
 static System::ServiceModel::Description::ServiceDescription ^ GetService(System::Object ^ serviceImplementation);
public static System.ServiceModel.Description.ServiceDescription GetService (object serviceImplementation);
static member GetService : obj -> System.ServiceModel.Description.ServiceDescription
Public Shared Function GetService (serviceImplementation As Object) As ServiceDescription

Parameters

serviceImplementation
Object

The Object that implements the service.

Returns

The ServiceDescription for the service object provided.

Exceptions

serviceImplementation is null.

Examples

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
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();
' 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)
Dim d As ServiceDescription = ServiceDescription.GetService(GetType(CalculatorService))
For Each isb As IServiceBehavior In d.Behaviors
    Console.WriteLine(CType(isb, Object).GetType())
Next isb
Console.WriteLine()

Remarks

Use this method to reflect on behaviors using the Windows Communication Foundation (WCF) 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.

Applies to

GetService(Type)

Returns a service description initialized with a specified service type.

public:
 static System::ServiceModel::Description::ServiceDescription ^ GetService(Type ^ serviceType);
public static System.ServiceModel.Description.ServiceDescription GetService (Type serviceType);
static member GetService : Type -> System.ServiceModel.Description.ServiceDescription
Public Shared Function GetService (serviceType As Type) As ServiceDescription

Parameters

serviceType
Type

The Type of the service.

Returns

The ServiceDescription for the service type provided.

Exceptions

serviceType is null.

Examples

ServiceDescription d = ServiceDescription.GetService(new CalculatorService());
foreach (IServiceBehavior isb in d.Behaviors)
{
    Console.WriteLine(isb.GetType());
}
Console.WriteLine();
Dim d As ServiceDescription = ServiceDescription.GetService(New CalculatorService())
For Each isb As IServiceBehavior In d.Behaviors
    Console.WriteLine(CType(isb, Object).GetType())
Next isb
Console.WriteLine()

Remarks

Use this method to reflect on behaviors using the Windows Communication Foundation (WCF) programming model when replacing ServiceHostBase with you own hosting mechanism.

GetService(Type) initializes the Name, Namespace, and ConfigurationName properties, reflects on the type for any the ServiceBehaviorAttribute objects and adds them to Behaviors, and ensures that the ServiceBehaviorAttribute is attached to the service.

Applies to