• Home
  • Privacy Policy
  • Terms & Conditions
  • Contact
  • Advertise
Videos, Photos, Wallpapers, Free Download, Movies, Songs, Sports , Live TV, Entertainment
 
  • Home
  • Bollywood
  • Hollywood
  • Box Office
  • Beauty
  • Fashion
  • Celebrity
  • Business
    • Social Media
    • Money Online
    • Category
  • Entertainment
    • Bollywood
  • Video
    • Youtube
    • Video
  • Technology
    • Asp.net
    • C#
    • SQL
    • .Net
Showing posts with label Web services. Show all posts
ASP.net Technology

Class Library

ASP.NET includes an enormous class library which was built by Microsoft. Because this class library is so large, it encapsulates a a huge number of common functions. For example, if you wanted to retrieve data from a database and display that data in a simple grid control through classic ASP, then you'd have to write quite a lot of code.

In ASP.NET, you don't write any code to display the data: you just write the code to bind the data to an object called a DataGrid (which can be done in just a couple of lines). Then, you just have to create a reference on your page to where that DataGrid should go. The DataGrid will be rendered as a table, and will contain all of the data extracted from the database.

Microsoft has created an amazingly well designed MSDN library for ASP.NET and all of the other .NET languages. It includes a full class library containing information and examples on every class, function, method, and property accessible through ASP.NET.

Web Services

Great feature of ASP.NET is Web Services. Web services mean that you can literally have several pieces of your application on different servers all around the world, and the entire application will work perfectly and seamlessly. Web services can even work with normal .NET Windows applications. For example: A lot of people would like to have a stock ticker on their web site, but not many people want to manually type in all changes to the prices. If one company (a stock broker) creates a web service and updates the stock prices periodically, then all of those people wanting the prices can use this web service to log in, run a function which grabs the current price for a chosen company, and return it.

Complete Compatibility

Important goals of .NET was to allow developers to write an ASP.NET application using multiple programming languages. As long as each ASP.NET page contains only one programming language, you can mix and match different pages using different languages and they will work together seamlessly. This means you can now have a team of developers with half programming in C#, and the other half in VB.NET, with no need to worry about language incompatibilities, etc.

A cool little side-affect of all this is that all the programming languages look very similar, and differ only by their language syntax.

First is written in C#, and the second in VB.NET.

The C# version:
void Page_Load(Object S, EventArgs E) { myLabel.Text = "ASP.NET Tutorial!";


The VB.NET version:
Sub Page_Load(S As Object, E As EventArgs) myLabel.Text = "ASP.NET Tutorial!"
End Sub

Difference between ASP.NET web service and programming WCF services like ASP.NET web services.

The development of web service with ASP.NET relies on defining data  and relies on the XmlSerializer to transform data to or from a service.

WCF (or Windows Communication Foundation) is a union of technologies developed by Microsoft to make it easier and quicker for developers to build distributed applications. WCF builds on the existing technologies of ASMX, .NET Remoting, MSMQ and DCOM. WCF attempts to unify these technologies and harness the power of all, while simplifying the process of implementation.

how to create a WCF Service, and how to consume it within an ASPX page. To demonstrate WCF, we will create a simple Operation Contract, which is similar to a Web Method, that we will call from our ASPX page. We can even expose the methods of the service to JavaScript, so that we can use them client-side.

using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1
{
// Add [WebGet] attribute to use HTTP GET
[OperationContract]
public void DoWork()
{
// Add your operation implementation here
return;
}

// Add more operations here and mark them with [OperationContract]
}

Key issues with XmlSerializer to serialize .NET types to XML

    Only Public fields or Properties of .NET types can be translated into XML.
    Only the classes which implement IEnumerable interface.
    Classes that implement the IDictionary interface, such as Hash table can not be serialized.

The WCF uses the DataContractAttribute and DataMemeberAttribute to translate .NET FW types in to XML.

    [DataContract]
    public class Item
    {
    [DataMember]
    public string ItemID;
    [DataMember]
    public decimal ItemQuantity;
    [DataMember]
    public decimal ItemPrice;

    }

The DataContractAttribute can be applied to the class or a strcture. DataMemberAttribute can be applied to field or a property and theses fields or properties can be either public or private.

Important difference between DataContractSerializer and XMLSerializer.

    A practical benefit of the design of the DataContractSerializer is better performance over XMLserialization.
    XMLSerialization does not indicate the which fields or properties of the type are serialized into XML where as DataCotratSerializer Explicitly shows the which fields or properties are serialized into XML.
    The DataContractSerializer can translate the HashTable into XML.

Developing Service

To develop a service using ASP.NET we must add the WebService attribute to the class and WebMethodAttribute to any of the class methods.



    [WebService]
    public class Service : System.Web.Services.WebService
    {
    [WebMethod]
    public string Test(string strMsg)
    {
    return strMsg;
    }
    }

To develop a service in WCF we will write the following code

    [ServiceContract]
    public interface ITest
    {
    [OperationContract]
    string ShowMessage(string strMsg);
    }
    public class Service : ITest
    {
    public string ShowMessage(string strMsg)
    {
    return strMsg;
    }
    }

The ServiceContractAttribute specifies that a interface defines a WCF service contract, OperationContract Attribute indicates which of the methods of the interface defines the operations of the service contract.

A class that implements the service contract is referred to as a service type in WCF.

Hosting the Service

ASP.NET web services are compiled into a class library assembly and a service file with an extension .asmx will have the code for the service. The service file is copied into the root of the ASP.NET application and Assembly will be copied to the bin directory. The application is accessible using url of the service file.

WCF Service can be hosted within IIS or WindowsActivationService.

    Compile the service type into a class library
    Copy the service file with an extension .SVC into a virtual directory and assembly into bin sub directory of the virtual directory.
    Copy the web.config file into the virtual directory.

Client Development

Clients for the ASP.NET Web services are generated using the command-line tool WSDL.EXE.

WCF uses the ServiceMetadata tool(svcutil.exe) to generate the client for the service.

Message Representation

The Header of the SOAP Message can be customized in ASP.NET Web service.

WCF provides attributes MessageContractAttribute , MessageHeaderAttribute and MessageBodyMemberAttribute to describe the structure of the SOAP Message.

Service Description

Issuing a HTTP GET Request with query WSDL causes ASP.NET to generate WSDL to describe the service. It returns the WSDL as response to the request.

The generated WSDL can be customized by deriving the class of ServiceDescriptionFormatExtension.

Issuing a Request with the query WSDL for the .svc file generates the WSDL. The WSDL that generated by WCF can customized by using ServiceMetadataBehavior class.
Older Posts Home

ASP.NET Examples

 
2012 24x7 Magazine. All rights reserved.
Designed by 24x7 Magazine