Sunday, January 31, 2010

SOA - Service Orientation

1. What is SOA ?
a, An SOA consists of a set of resources on a network that are made available as independent services , and that can be accessed without required any knowledge of how they are implemented.
b, We can combine the services in an SOA to create an enterprise application.

2. What are the benefits of SOA ?
Ans: It enables you to create complex solutions that are independent of any specific platform. and location. that is you can quickly replace or upgrade a service or move a service to a different site. and as long as the service exposes the same interfaces as before, you can continue to use it without needing to modify any code.

3. What are the 4 tenets of Service Orientation which are required to solve the Distributed application architecture problems and to successfully design and implement an SOA?
1. Boundaries are Explicit: We should not make any assumptions about how a service processes a request or how a client application handles any response to a request . Following this principle removes any dependencies between the client and service applications.
2. Services are autonomous: We should design our solutions to be loosely coupled, so that they can tolerate the changes (Location of a service might change, or service might be taken offline for maintenance purposes or for other reasons). and continue running even if one or more services are unavailable.
3. Services share schemas and contracts, not classes or types. If you need to modify a service and provide additional functionality, you can add contracts and schemas that extend the original capabilities of the service while retaining the existing contracts and schemas. Older client applications should continue to work unchanged.
4. Compatibility is based on policy: You should design services so that their policy requirements are independent of any implementation, and you should enforce clients to abide by any policies required by the service. Additionally, all services and client applications must agree on how to specify this policy information (typically by using some sort of configuration file). This is the purpose of the WS-Policy framework.

WCF Fundamentals continued

1. What are the two templates Visual Studio provides to create a WCF Service ?
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.
a. The section contains the configuration information for a WCF Web service.
b. The section contains the details for each service implemented.
c. The name attribute of the element specifies the namespace and class the implements the service.
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 element to true.



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 element to true.
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.

WCF Fundamentals

1. Why WCF ?
Answer: The purpose of WCF is to provide a unified programming model for many of these technologies, enabling you to build applications that are as independent as possible from the underlying mechanism being used to connect services and applications together.
using WCF enables you to maintain backwards compatibility with many of the preceding technologies. For example, a WCF client application can easily communicate with a Web service that you created by using WSE
WCF enables you to build powerful service-oriented systems, based on connected services and applications. You can use WCF to create new services, as well as add new functionality and interoperate with the functionality available through many existing services created by using other technologies. WCF provides a consistent model for using a variety of technologies, enabling you to design and architect your solutions without being restricted by a specific connectivity mechanism.

2. Which account is used by IIS to execute WCF Service?
Answer: IIS executes Web services using the ASPNET account under Windows XP, or the NETWORK SERVICE account under Windows Vista. This account must be able to read the contents of the folder holding the files for the service, as well as the parent folder hierarchy.

3. How does an application know how to format data so that another application can read it correctly?
Answer: Both Client and Server applications have to agree on a layout. This layout is referred to as the XML schema for the data.

4. Why we use XML in WCF Services ?
Answer: To share data successfully between applications running on different computers, developers had to agree on a common format for that data that was independent of the architecture of the computer they were using. Therefore We use XML.

5. What is XML?
Ans: XML is text-based and human-readable, and lets you define a grammar for describing just about any type of data that you need to handle

WCF Basics

Above XML data actually means, An application that needs to send information about a Book to another application could format the data in this way, and the receiving application should be able to parse the data and make sense of it. However, there is more than one way to represent this information by using XML. You could also structure it like this:

6. How does an application know how to format data so that another application can read it correctly?
Ans: application sending the data, uses XML schema to convey information about how the data it is emitting is structured, and the application receiving the data can use this schema to help parse the data in xml file and make sense of it.

By adopting XML and schemas as a common data format, applications running on different computers can understand the data that they are using.

7.What is WSDL Document ?
Answer: A WSDL document is an XML document that conforms to a standard XML schema and that describes the messages the Web service can accept and the structure of the responses it will send back. A client application can use this information to determine how to communicate with the Web service.

8. What is the difference between Security and Privacy ?
Answer: Security is concerned with identifying users and services and then authorizing their access to resources.
There are number of standard mechanisms for implementing security, such as using username/password pairs, X509 certificates, and Kerberos tokens.

Privacy: When applications communicate on Internet. You don't want other users to be able to intercept and read the messages flowing between your applications and Web services. this means encrypting the messages that they exchange using Public and Private Keys.

Monday, January 18, 2010

error: Access is denied to the path specified.

When deleting a file in, Getting the error: Access is denied to the path specified.

1. Add aspnet account and give full permissions to the specified folder.
2. Right click the folder in which file is present. Go to General tab and uncheck Readonly option.
3. In security Tab give write control for Network Service

Now, try accessing the file. It should work.

Thursday, January 14, 2010

posting the aspx page to server using javascript

How to postback the aspx page to server Using Javascript posting and raise an Event.

Resolution: Below code will post back the form to server and raises the TextChanged Event handler of TextBox1 if defined in the aspx.cs file.
This code must be written in Head section of aspx page in javascript tag.

__doPostBack('window.document.forms[0]. TextBox1','TextChanged');