InstanceContext.GetServiceInstance Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns the instance of the service.
Overloads
GetServiceInstance() |
Returns the instance of the service for the instance context. |
GetServiceInstance(Message) |
Returns the instance of the service for the instance context in response to an incoming message. |
GetServiceInstance()
Returns the instance of the service for the instance context.
public:
System::Object ^ GetServiceInstance();
public object GetServiceInstance ();
member this.GetServiceInstance : unit -> obj
Public Function GetServiceInstance () As Object
Returns
The object that represents the service instance.
Exceptions
The service instance is in a created or opening state or is not initialized.
The service instance is aborted.
The service instance has been closed already and cannot be modified in these states.
The service instance is faulted and cannot be modified in these states.
Examples
Uri baseAddress = new Uri("http://localhost:8000/ServiceModelSamples/service");
// Create a ServiceHost for the CalculatorService type and provide the base address.
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress))
{
serviceHost.Open();
OperationContext operationContext = OperationContext.Current;
InstanceContext instanceContext = operationContext.InstanceContext;
CalculatorService service = (CalculatorService) instanceContext.GetServiceInstance();
}
Applies to
GetServiceInstance(Message)
- Source:
- InstanceContext.cs
- Source:
- InstanceContext.cs
- Source:
- InstanceContext.cs
Returns the instance of the service for the instance context in response to an incoming message.
public:
System::Object ^ GetServiceInstance(System::ServiceModel::Channels::Message ^ message);
public object GetServiceInstance (System.ServiceModel.Channels.Message message);
member this.GetServiceInstance : System.ServiceModel.Channels.Message -> obj
Public Function GetServiceInstance (message As Message) As Object
Parameters
- message
- Message
The incoming message that triggered the creation of a service object.
Returns
The object that represents the service instance.
Exceptions
The service instance is in a created or opening state or is not initialized.
The service instance is aborted.
The service instance has been closed already and cannot be modified in these states.
The service instance is faulted and cannot be modified in these states.
Examples
Uri baseAddress = new Uri("http://localhost:8000/ServiceModelSamples/service");
// Create a ServiceHost for the CalculatorService type and provide the base address.
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress))
{
serviceHost.Open();
OperationContext operationContext = OperationContext.Current;
InstanceContext instanceContext = operationContext.InstanceContext;
CalculatorService service = (CalculatorService)instanceContext.GetServiceInstance(msg);
}
Remarks
The general idea is that you only create an instance of the service when a message directed at it arrives, by calling Open; then if no message arrives, no InstanceContext is created and no service object is created, and so resources are not deployed until actually required.
Applies to
.NET
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示