Permalink
Fetching contributors…
Cannot retrieve contributors at this time
121 lines (110 sloc) 7.16 KB
<Type Name="InstanceContextMode" FullName="System.ServiceModel.InstanceContextMode">
<TypeSignature Language="C#" Value="public enum InstanceContextMode" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi sealed InstanceContextMode extends System.Enum" />
<TypeSignature Language="DocId" Value="T:System.ServiceModel.InstanceContextMode" />
<TypeSignature Language="VB.NET" Value="Public Enum InstanceContextMode" />
<TypeSignature Language="C++ CLI" Value="public enum class InstanceContextMode" />
<TypeSignature Language="F#" Value="type InstanceContextMode = " />
<AssemblyInfo>
<AssemblyName>System.ServiceModel</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Enum</BaseTypeName>
</Base>
<Docs>
<summary>Specifies the number of service instances available for handling calls that are contained in incoming messages.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.ServiceModel.InstanceContext?displayProperty=nameWithType> manages the association between the channel and the user-defined service objects. Use the <xref:System.ServiceModel.InstanceContextMode> enumeration with the <xref:System.ServiceModel.ServiceBehaviorAttribute.InstanceContextMode%2A?displayProperty=nameWithType> property to specify the lifetime of the <xref:System.ServiceModel.InstanceContext> object. Windows Communication Foundation (WCF) can create a new <xref:System.ServiceModel.InstanceContext> object for every call, every session or specify that the <xref:System.ServiceModel.InstanceContext> object is bound to a single service object. For a working example, see the [Instancing](~/docs/framework/wcf/samples/instancing.md).
The Single value specifies that a single <xref:System.ServiceModel.InstanceContextMode.Single> object should be used for the lifetime of the service.
> [!NOTE]
> If the <xref:System.ServiceModel.ServiceBehaviorAttribute.InstanceContextMode%2A> value is set to Single the result is that your service can only process one message at a time unless you also set the <xref:System.ServiceModel.ServiceBehaviorAttribute.ConcurrencyMode%2A> value to <xref:System.ServiceModel.ConcurrencyMode>.
## Examples
The following code illustrates how to set the <xref:System.ServiceModel.InstanceContextMode> for a service class:
[!code-csharp[S_ReliableSession#1](~/samples/snippets/csharp/VS_Snippets_CFX/s_reliablesession/cs/service.cs#1)]
[!code-vb[S_ReliableSession#1](~/samples/snippets/visualbasic/VS_Snippets_CFX/s_reliablesession/vb/service.vb#1)]
]]></format>
</remarks>
<altmember cref="P:System.ServiceModel.ServiceBehaviorAttribute.InstanceContextMode" />
<altmember cref="P:System.ServiceModel.OperationBehaviorAttribute.ReleaseInstanceMode" />
</Docs>
<Members>
<Member MemberName="PerCall">
<MemberSignature Language="C#" Value="PerCall" />
<MemberSignature Language="ILAsm" Value=".field public static literal valuetype System.ServiceModel.InstanceContextMode PerCall = int32(1)" />
<MemberSignature Language="DocId" Value="F:System.ServiceModel.InstanceContextMode.PerCall" />
<MemberSignature Language="VB.NET" Value="PerCall" />
<MemberSignature Language="C++ CLI" Value="PerCall" />
<MemberSignature Language="F#" Value="PerCall = 1" Usage="System.ServiceModel.InstanceContextMode.PerCall" />
<MemberType>Field</MemberType>
<AssemblyInfo>
<AssemblyName>System.ServiceModel</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.ServiceModel.InstanceContextMode</ReturnType>
</ReturnValue>
<MemberValue>1</MemberValue>
<Docs>
<summary>A new <see cref="T:System.ServiceModel.InstanceContext" /> object is created prior to and recycled subsequent to each call.</summary>
</Docs>
</Member>
<Member MemberName="PerSession">
<MemberSignature Language="C#" Value="PerSession" />
<MemberSignature Language="ILAsm" Value=".field public static literal valuetype System.ServiceModel.InstanceContextMode PerSession = int32(0)" />
<MemberSignature Language="DocId" Value="F:System.ServiceModel.InstanceContextMode.PerSession" />
<MemberSignature Language="VB.NET" Value="PerSession" />
<MemberSignature Language="C++ CLI" Value="PerSession" />
<MemberSignature Language="F#" Value="PerSession = 0" Usage="System.ServiceModel.InstanceContextMode.PerSession" />
<MemberType>Field</MemberType>
<AssemblyInfo>
<AssemblyName>System.ServiceModel</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.ServiceModel.InstanceContextMode</ReturnType>
</ReturnValue>
<MemberValue>0</MemberValue>
<Docs>
<summary>A new <see cref="T:System.ServiceModel.InstanceContext" /> object is created for each session. If the channel does not create a session this value behaves as if it were <see cref="F:System.ServiceModel.InstanceContextMode.PerCall" />.</summary>
</Docs>
</Member>
<Member MemberName="Single">
<MemberSignature Language="C#" Value="Single" />
<MemberSignature Language="ILAsm" Value=".field public static literal valuetype System.ServiceModel.InstanceContextMode Single = int32(2)" />
<MemberSignature Language="DocId" Value="F:System.ServiceModel.InstanceContextMode.Single" />
<MemberSignature Language="VB.NET" Value="Single" />
<MemberSignature Language="C++ CLI" Value="Single" />
<MemberSignature Language="F#" Value="Single = 2" Usage="System.ServiceModel.InstanceContextMode.Single" />
<MemberType>Field</MemberType>
<AssemblyInfo>
<AssemblyName>System.ServiceModel</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.ServiceModel.InstanceContextMode</ReturnType>
</ReturnValue>
<MemberValue>2</MemberValue>
<Docs>
<summary>Only one <see cref="T:System.ServiceModel.InstanceContext" /> object is used for all incoming calls and is not recycled subsequent to the calls. If a service object does not exist, one is created.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
> [!NOTE]
> For singleton lifetime behavior (for example, if the host application calls the <xref:System.ServiceModel.ServiceHost.%23ctor%2A> constructor and passes an object to use as the service), the service class must set <xref:System.ServiceModel.ServiceBehaviorAttribute.InstanceContextMode%2A> to Single, or an exception is thrown when the service host is opened.
]]></format>
</remarks>
</Docs>
</Member>
</Members>
</Type>