SOA stands for Service Oriented Architecture. It has the following important tenets:-
1) Services have explicit boundary.
2) Services are autonomous.
3) Services expose Operation Contract and Data schema but not the type specific metadata.
4) Services are compatible based on clear policies.
What is WCF ?
WCF stands for Windows Communication Framework. WCF facilitates interoperability between clients and services having similar or dissimilar configurations. WCF provides a runtime which manages hosting, service instance management, asynchronous calls, transaction management, type-safety, message reliability, concurrency, and security.
What is the difference between Web Service and WCF?
Web Service WCF
Can use HTTP Transport Protocol only Can use HTTP, TCP, MSMQ, NamedPipe etc
Explain Metadata ?
WCF services use metadata to describe how to interact with the service's endpoints so that tools, such as Svcutil.exe, can automatically generate client code for accessing the service. WCF metadata infrastructure reside in the System.ServiceModel.Description namespace.
• WCF represents the metadata for a service as an instance of the MetadataSet type, the structure of which is strongly tied to the metadata serialization format defined in WS-MetadataExchange.
• The MetadataSet type bundles the actual service metadata, such as Web Services Description Language (WSDL) documents, XML schema documents, or WS-Policy expressions, as a collection of MetadataSection instances.
• Each System.ServiceModel.Description.MetadataSection instance contains a specific metadata dialect and an identifier and can contain the following items in its Metadata property:
o Raw metadata.
o A MetadataReference instance point to another metadata exchange (MEX) endpoint
o A MetadataLocation instance point to a metadata document using an HTTP URL.
How to publish MetaData endpoint ?
Add the ServiceMetadataBehavior service behavior to expose metadata endpoints that support the MEX protocol or that respond to HTTP/GET requests. Can be done through code and configuration.
ServiceMetadataBehavior uses a WsdlExporter to export metadata for all service endpoints in your service. ServiceMetadataBehavior adds a ServiceMetadataExtension instance as an extension to service host. The ServiceMetadataExtension provides the implementation for the metadata publishing protocols. ServiceMetadataExtension helps to get the service's metadata at runtime by accessing the System.ServiceModel.Description.ServiceMetadataExtension.Metadata property.
Code : http://msdn.microsoft.com/en-us/library/aa738489.aspx
Config : http://msdn.microsoft.com/en-us/library/ms734765.aspx
What is meta data exchange ?
Web Services have to expose metadata so that clients can understand how to interact with and make use of that service endpoint.This metadata is generally exchanged in the form Web Services Description Language(WSDL) and XSD schemas describing the bindings,network addresses,messages to be exchanged & also operations and data types.
http://sankarsan.wordpress.com/2010/06/20/wcf-metadata-exchange-part-1/
What is WCF Address ?
Provides two things
• Location tells the name of target machine, site, network, comm port, pipe, queue, URI.
• Transport protocol/schema
What are diff types of Transport schema ?
• HTTP default port 80 and for HTTPS 443
• TCP (default port 808)
• MSMQ(net.msmq)
• Peer network(net.p2p)
• IPC ( uses net.pipe and uses windows named pipe mechanism and from same machine)
Explain Binding ?
Describe the optimal choice of transport protocol, message encoding, comm pattern, reliability, security transaction, and interop. Binding allows same service logic over various plumbings. Service publishes its bindings in its metadata, enabling client to query for the type and specific props of bindings. It is important bcoz client and service binding must match.
Explain Contract ?
Is platform neutral and standard way of what service does.
What are the diff types of contracts ?
• Service ( operations )
• Data ( data types)
• Fault ( regarding errors)
• Message ( for interoperability when a party has pre-defined proprietary message format)
How Service Contract is implemented?
• [ServiceContract] attribute exposes a CLR Interface as WCF Contract.
• Can be directly applied on the Service class
Restrictions on OperationContract
• Can be applied only on methods, and not on properties, indexers, or events.
• Cannot use object reference as parameters: only primitive types or data contacts are allowed.
• Can be applied on private as well as public class
• Avoid parametrized constructors as WCF only uses default constructor.
Explain Hosting
Every WCF service must be hosted in a Windows process called the host process.
Host can be provided by
• Self hosting
• IIS
• Windows Activation Service. ( part of IIS 7, but can use other transport mech apart from HTTP)
Self hosting
• WCF provides a hook in the srvice class to access the host using Factory tag in .svc file.
• Host factory class must derive from ServiceHostFactory and override CreateServiceHost() virtual method.
IIS Hosting
• Usage : create a virtual directory under IIS and provide a .svc file.
• Advantage : process is launched automatically upon the first client request
• Disadvantage : can only use HTTP and all service use the same port number with IIS 5.
ServiceHost class
• Need to provide the constructor of ServiceHost class with service type and optional base addresses.
• Each ServiceHost class is associated with a matching service type so for multiples types we need multiple ServiceHost.
• Worker thread are involved. I/O thread pool has 1000 threads by default.
• CloseTimeout can be specified on host in code or config
• Can also call a Abort() method.
Explain Channels ?
• Can use Channel directly to invoke operations on a service, without ever using a proxy class.
• ChannelFactory
• Use ChannelFactory and its method CreateChannel() method to get a proxy.
• CreateChannel may accept binding and endpointAddress.
What is reliable messaging? Explain diff btn transport reliability and message reliability?
Transport Reliability offers point to point guaranteed delivery at the network packet level and also in order delivery of the packets. It cannot operate while there is connection problem.
Message Reliability offers end to end delivery of message in the required or correct order and also irrespective of any intermediaries from client to service. It deals with connection issues.
Which Bindings have/don’t have support for Reliability ?
Reliability is not supported by BasicHttpBinding , NetMsmqBinding
Reliability is supported by WSDualHttpBinding, NetTcpBinding, WSHttpBinding, NetNamedPipeBinding
How you configure the same in config file and through code?
binding
What are the diff bindinds that supports reliability ?
WsHttpbinding , wsdualhttpbinding, wsfederationbindibg, tcpnetbinding
What is the use of KnownType and ServiceKnownType attribute ?
KnownType is used in the DataContract while the ServiceKnownType is used in the Service Contract level. WCF formatter uses reflection to collect all the known types of the data contracts, and then examine the provided parameter to see if it is any of the known types.
Usage : [ServiceKnownType(typeof(SomeClass)]
What are the Disavantages of using ServiceKnownType attribute ?
Client and server both should know all possible subclasses. Adding new classes require code change, recompiling and redeploying.
How to configure KnownType in config file?
Can we use Enumeration type with WCF ?
Enumerations, including flag enumerations, are serializable. Optionally, enumeration types can be marked with the DataContractAttribute attribute, in which case every member that participates in serialization must be marked with the EnumMemberAttributeattribute. Members that are not marked are not serialized.
Can we use Arraylist with WCF ?
Yes.
Can we use DataTable and DataSet with WCF ?
Yes, but the question is it a good idea....No.. Its not bcoz the internal structure of DT and DS are very complex with additional info about the relationship, so its best to use Array, rather than DT or DS.
How are the collections in WCF service is exposed to the client ?
As an Array.
What is CollectionDataContract ?
It exposes the collection to the client as a generic linked list.
What are the different types of InstanceContextMode ? or
What are the different types of instance activation ?
• Per call
• Per Session
• Singleton
How to configure InstanceContextMode ?
ServiceBahavior(InstanceContextMode= InstanceContextMode.PerCall)
What is a Behavior ?
It extends or affects the way a service is executed.
What are the types of behavior attributes ?
• ServiceBehavior
• OperationBehavior
What is Transport session ?
What are the different SessionMode ?
• Allowed (default)
• Required
• NotAllowed
How SessionMode is applied?
It is applied on the Contract and Service level. [ServiceContract(SessionMode = SessionMode.Required)]
What is a Session ID ?
Session ID is an unique identifier to identify a session and it can be accessed in both Server and Client end. Service can access it as OperationContext.Current.SessionId and Client can access it as proxy.InnerChannel.SessionId.
When is Singleton disposed?
Only when the host is shut down.
How can a client get the Host object?
OperationContext.Current.Host.
What are the different ReleaseInstanceMode ?
• None
• BeforeCall
• AfterCall
• BeforeAndAfterCall
What is Durable service ?
Services that store the service state information in database and retrieve it even when the service or client is restarted. Durable service is implemented using DurableService attribute and its two properties : CanCreateInstance or CanCompleteInstance.
What is an InstanceId in context of Durable service ?
It uniquely identifies the state of the server object.
How the persistence is taken care for Durable Service ?
WCF uses Bridge pattern in the form of provider model, which lets you specify the state store separately from the attribute. The host must be configured with a persistence provider factory. The specific class is PersistenceProviderFactory derived from CommunicationObject.
How to configure SQL Server as a persistence provider ?
What is throttling ?
It enables to avoid maxing out of service and the underlying resources it uses or allocates. WCF automatically puts the pending callers in a queue as soon as the condition in the configuration meets.
What are the different throttling parameters ?
• maxConcurrentCalls [default = 16]
• maxConcurrentSessions[default = 10]
• maxConcurrentInstances.
How throttling is handled in code ?
ServiceThrottlingBehavior = host.Description.Behaviors.Find
What are different type of WCF Operation ?
WCF supports following 3 types of Message Exchange Patterns
• Request - reply (default message exchange pattern)
• OneWay (Simplex / datagram)
• Duplex(CallBack)
Explain Request-Reply?
Client issues a request and blocks until it gets the reply back. TimeoutException will be thrown at client in case the default timeout if 1 min is reached.
Explain One-way ?
When client doesnot cares about the response or the operation has no return value.
What attribute is used to support One-Way ?
OperationContract(IsOneWay=true)]
What are Callbacks in WCF ?
Also called duplex, is the mechanism by which Service can call back its client. They are useful in notifying (event) to the client that something has happened on the service side. Uses Duplex operation.
Which bindings has support or no support for duplex or callbacks?
• No support : basicHttpBinding and wsHttpBinding
• Has Support : wsDualHttpBinding, netTcpBinding, netNamedPipeBinding.
Explain CallbackContract ?
Used with ServiceContract attribute, it is used to define the type of callback contract.
What is Duplex proxy ?
Needed to setup at the client-side to invoke duplex communication. The client need to derive from DuplexClientBase
Explain types of concurrency mode ?
All the modes are used with ServiceBehavior attribute.
• Single(default)
• Reentrant
• Multiple
In Reentrancy, service instance context is still associated with a lock, and only single-threaded access is allowed. However, when server calls the client, WCF releases the lock first.
What is streaming in WCF ?
Streaming transfer mode is the processing of the data in the message while the message is still being received( on server or client channel). Generally used with huge data which takes a lot of time to load. Neither the receiver nor the sender is blocked.
Which transport scheme supports streaming ?
TCP, IPC, HTTP. All have streaming disabled by default. Can be enabled using TransferMode property.
What are the diff TransferMode ?
• Buffered
• Streamed
• StreamedRequest
• StreamedResponse.
Explain MaxReceivedMessageSize ?
Can be used to increase the max msg size. Default is 64K.
What does ConcurrencyMode.Multiple means ?
WCF will not queue up the client messages but will dispatch them to the service instance as soon as they arrive.