1. If you are creating a WCF service that is always going to be deployed by using IIS, then you could use the WCF Service Template. Here the service is automatically deployed to IIS or The Visual Studio Development server depending on the options that you select.
2. WCF Service Library template : The Service built can be deployed not only in IIS but can be reused in various other scenarios. i.e., deploying WCFService in other applications.
2. What is the significance of System.ServiceModel namespace ?
Ans: It contains the classes used by WCF for defining services and their operations.
3. Why WCF uses the namespace: System.Runtime.Serialization ?
Ans: WCF uses the classes in the System.Runtime.Serialization namespace to convert objects into a stream of data for transmitting over the network (a process known as serialization) and to convert a stream of data received from the network back into objects (deserialization).
4. What is System.IdentityModel namespace used for?
Ans: This assembly contains namespaces and types that you-can use to manage security and identity information, helping to protect a WCF service.
5.What is Contract-First approach ?
Ans: First we define the interfaces, or contracts, that the service will implement and then build a service that conforms to these contracts.
It enables you to concentrate on the design of your service. If necessary, it can quickly be reviewed to ensure that it does not introduce any dependencies on specific hardware or software before you perform too much development because in many cases client applications might not be built using WCF, or even be running on Windows.
6. What is Service Contract ?
Ans: It defines the operations that the WCF Service will implement. WCF defines the shape of the WCF service by using a service contract.
7. What is DataContract ?
Ans: The data contract specifies the structure of user defined types that the WCF service can pass to operations.
8. What does DataContract attribute specify ?
Ans: The DataContract attribute identifies the class as defining a type that can be serialized and deserialized as an XML stream by WCF. All types that you pass to WCF operations or return from WCF operations must be serializable by WCF. You can apply the DataContract attribute to classes, structures, and enumerations.
Mark each member of the type that has to be serialized with the DataMember attribute; any members not tagged in this way will not be serialized.
Basic datatypes such as string,int, decimal and complex types such as collection classes are already defined as serializable in dotnet framework i.e. they already have datacontract defined for them.
9. What is Operation Contract ?
Ans: Each method that you want to expose to the client should be tagged with the OperationContract attribute.
10. How to run a WCF Service ?
Ans: You must host a WCF Service in an application in order to run it. and then make it accessible to clients.
11. How to host a WCF Service ?
Ans: The different ways in which WCF Service can be hosted are :
1. By Creating a Custom Host Application.
2. By building a Windows Service Application.
3. Using IIS.
12. What is a Service Definition File ?
Ans: This file specifies the name of the class that IIS will execute and the name of the assembly holding this class. Service Definition File must have the same name as the web service and must have the svc suffix. This file contains ServiceHost directive and Assembly directive as shown in the example below
Ex: <%@ServiceHost Service="Orders.OrdersServiceImpl" %>
<%@Assembly Name="OrdersService" %>
1. Here, The Service attribute of the ServiceHost directive specifies the namespace (Orders) and the class (OrdersServiceImpl) that implements the service.
2. The Assembly directive specifies the name of the assembly (OrdersService) containing this namespace and class .
13. What end point information is present in the Web.config file of a WCF Service ?
Ans: It contains binding information for the WebService specifying
a. The contract that the Service will implement.
b. How a client should communicate with the service.
14. Explain the main sections present in the web.config file of a WCF Service.
c. The name attribute of the
d. The endpoint element provides the details of the service that client applications require in order to communicate with the service.
e. An enpoint consists of three pieces of information: Address, Binding and Contract.
f. The address is the location that the application hosting the service uses to advertise the service.
g. In case of IIS, address element is ignored as IIS will use a URL containing the name of the Virtual Directory holding the service and the name of the .svc file as the endpoint.
h. The binding comprises of
i. Transport mechanism used to access the Webservice.
ii. The Protocol to use.
i. We can also specify any of the Standard bindings built into WCF that implement preconfigured binding information.
j. The contract element indicates the contract that the service implements.
15. How client applications can determine the operations the service implements ?
Ans: Client applications require access to the metadata of a service so that they can determine the operations the service implements. for this the Service must publish the Metadata. and the client application must query the service to obtain the metadata.
16. How does a service publish metadata ?
Ans: By setting the httpGetEnabled attribute of the
In the Service element under Services section, set the behaviorConfiguration property to OrdersBehavior.
This will add a behaviour called OrderBehavior to the service. A serviceBehavior extends the functionality of the service.
Thus, The definition of the OrdersBehavior behavior enables metadata publishing by setting the httpGetEnabled attribute of the
This enables us to view the WSDL document containing the metadata description of the service. which is in XML format.
Visual studio can query the service and use this info. to generate a proxy class when building a WCF Client Application.