Quiz for WCF software developers
Name the WCF Instance Context Modes
Per Call, Per Session, Singleton
Why is it called Instance Context Mode instead of Instance Mode?
Because It controls the instantiation of the hosting context instead of the instance of the host.
The instance of the host is always up when opened but the service it is hosting, the context, gets instantiated at different times depending on its Instance context mode.
Where do you set the instance context Mode?
On the service behaviour defined on the service class.
Name the pro’s and cons of using instance context mode per call.
Improves resource sharing over a large user base.
Caters well to transactional programming.
Can be used in qued disconnected calls.
The service needs to load and saves its data per call. It’s a trade-off between performance and scalability.
Is a Per call service state full?
No, Per call services are State Aware not state full.
What is state aware?
Aware of storage – Loads state and saves state during each operation.
When is the per call instance disposed?
When the service operation has completing its processing.
Explain the pros and cons of Per Session instance context mode.
State full for the duration of the session.
The service hogs resources, Each service stays loaded for the duration of a session.
When is a per session service instance disposed?
When proxy closes or when proxy times out.
What architecture is per session instancing reminiscent of?
Client / Server
How does WCF go about matching a client up with the service associated with its session?
Each service has the session id of the client.
Where do you indicate if service supports per session.
Service behaviour on service class
Session mode on interface.
So what happens if the service behaviour is configured for per session and the service contract is set to session.NotAllowed?
When operation is requested the context exists for the session but the server instance is created for that call only.
Ok, so now you have a session behaviour set to session and the service contract is set to session.allowed – What else needs to match up to support per session calls.
Can all bindings / protocols support per session?
No. The binding must support a transport level session.
Name the bindings that support a per session type service.
- WebHttpBinding (only when reliable messaging is enabled)
What happens if the binding does not support per session.
it defaults to per call.
Statement – It is recommended to have consistent configurations. If the service supports session then all contracts and all endpoints should as well.
What is a singleton service?
All clients connect to the same instance if a service. There is only ever one of it.
When does a singleton service get disposed?
When the hosting process is closed or disposed.
What happens if the client closes its proxy, Is the service disposed?
Only the transport session between the client and the service is terminated, The service instance remains to run.
Is a Singleton service state full or state aware?
State full. It loads its state when the service starts up and maintains the state till the service is closed.
Name the Pros and cons of Singleton.
State full, only need to load to state its state once when the service starts up.
No resource sharing
Unable to Scale.
What are “Demarcating Operations”?
Attributes on the service operations which indicates the order in which operations should be called. It dictates the calling pattern – how the service should be used. Which operation should be called first and which should be called last.
What will happen to the state of the client proxy when the terminate operation is called?
Can the proxy continue to use the service/
The proxy will be invalid after a terminating operation has been called.
What is the Release Instance Mode?
It controls the lifetime of the InstanceContext.
What are the options for the release instance mode?