Thursday, May 31, 2012

Developing WCF Service

 To develop a WCF Service,we have to Follow below Steps:

  1. Creating a .Net Component which is compatable to WCF (WCF Runtime Enabled) to do this wcf provides different closes in the form of attributes, sothat we can attach them to component content.All these libraries and WCF Runtime is provided in System.ServiceModal.dll.  

    Eg:
    [ServiceContract]
    class Demo
    {
    [OperationContract]
     -------
    -------
    }

  2. Every service requires Hosting sothat it can manage the operating system and Other environment related issues.Remoting webservices provider simple (or)  single hosting options,which is restricting user to particular process.WCF provides rich hosting options,sothat  user can plan service where good management capabilities.

    WCF provides the following hosting options:

    •     Self Hosting.
    •     Windows Server Hosting
    •     IIS hosting
    •     WAS Hosting(Windows Activation Services)
  3. Endpoints for Accessing the Service:In Wcf a service is exposed to clients using an endpoint every client understands as well as communicater with wcf service using endpoint only.WCF provides endpoint as a type with 3 Parts:

    • Address: Here we specify the location where ourservice is available.Wcf follows industry standards addressing pattern so while writting addressing instead of .net style addressing .We have to write wcf style of address. 

    • Binding: It defines how to communicate with service.It includes the formatter channel and other information with just the binding name,that we specify.

      Eg: basicHttpBindind  means SOAP formate of coomunication using Http Channel.

    •  Contract: This is .Net type that we provide for clients for request and resonse.what methods and other content is provided in this contract.

      Eg: Google Search Service provides do google search method with many inputs and outputs,which are known to us with contract.

 


Tuesday, May 29, 2012

Developing Destributed Programs

.Net Supports for developing destributed programs:
                    i. .Net Remoting
                   ii.  Asp.Net Web Service
                   iii. WCF

.Net Remoting:

                         Remoting offers distributed programming between two .net apps.It has a fixed an architecture where different customigation is provided for development any distributed program developed with remoting libraries get good performance as well as security so any LAN and also WAN application.Which are .Net based can be developed using remoting infrastructer.

.Net Remoting

Public application i.e., an application in heterogeneous environment is not possible with Remoting.


*To Make the Remoting a firewall unrejectable,we use SOAP with Http Best Combination for Remoting is client,Proxy,binary,TCP because of best performance and best Security. IPC is the faster but worker only in one system.
To Know more about .Net Remoting click here.

Asp.Net Webservices:

      • It follows open standard XML webservices specification.
      • .Net To Run non .Net distributed app can be developed.
      • Originally lower in performance and security with additional installation/libraries.We can get secured environment but with less feature and performance.                                           
Asp.Net WebService

WCF Service:

 

Windows Communication Foundation

 


  • WCF Enabled .Net Component.
  • Hosting of WCF Service.
  • End Pont for accessing the service.
  • A service must have minimum one endpoint.
  • Endpoint contain Address,Binding and Contract


  • Windows Communication Foundation

    WCF

    Distributed Applications:

    Communication Between Multiple server Apps or Services in the Network. Must be capable to run bihind firewalls.


    Some share common protocals(SOAP,WSDL) but not a Common Platform.
    Features of Distributted Applications:

    Performance: very often a collection of processors can provide higher performance (and better
    price/performance ratio) than a centralized computer.
    Distribution: many applications involve, by their nature,spatially separated machines (banking,commercial, automotive system).
    Reliability (fault tolerance): if some of the machines crash, the system can survive.
    Incremental growth: as requirements on processing power grow, new machines can be added incrementally.
    Sharing of data/resources: shared data is essential to many applications (banking, computersupported cooperative work, reservation systems); other resources can be also
    shared (e.g. expensive printers).
    Communication: facilitates human-to-human communication.

    Disadvantages of Distributed Systems
    Difficulties of developing distributed software:
    how should operating systems, programming languages and applications look like?
    Networking problems: several problems are created by the network infrastructure, which have to
    be dealt with: loss of messages, overloading, ...Security problems: sharing generates the problem of data security.

    What is Service?
    • Self Contained business function.
    • Functionality exposed via a structured messaging scheme.
    • Not just XML,not just HTTP
              =>XML,SOAP,JSON,Images..etc
              =>TCP,HTTP,Message Queues...etc

    Thursday, May 17, 2012

    Ajax updatepanel example with triggers in asp.net

    Introduction:


    In this article I will explain what is Ajax updatepanel control, advantages of updatepanel control and how to use multiple updatepanels in asp.net.

    Description:

    Previously I explained many articles relating to 
    Ajax. Now I will explain what is ajax updatepanel control and use of ajax updatepanel control in asp.net.
    During work with our applications if we entered any values in textbox controls and click on a button in form we will see full postback of our page and we will lost all the controls values whatever we entered previously this happend because of postback. If we want to avoid this full postback of page and round trip to server we need to write much code instead of writing much code we can use ajax updatepanel control.
    Ajax updatepanel will help us to avoid full postback of the page i.e., avoid refresh of the whole page content with postback and stop flickering of the page which is associated with a postback and allows only partial postbacks. By using Ajax updatepanel we can refresh only required part of page instead of refreshing whole page.
    Ajax updatepanel contains property called UpdateMode this property is used to specify whether UpdatePanel is always refreshed during a partial render or if it refresh only when a particular trigger hit. By default updatepanel contains UpdateMode="Always" if we want to set it conditionally we need to change this property UpdateMode="Conditional"
    Ajax updatepanel control contains two child tags those are ContentTemplate and Triggers.
    ContentTemplate is used to hold the content of the page means suppose we designed page with some controls we will place controls inside of the ContentTemplate
    Triggers we used in a situation like need to refresh updatepanel only whenever I click some button control in that situation I will define those controls with this Triggers child tag.
    Our Sample update panel control will be like this
    <asp:UpdatePanel ID="UpdatePanel2" runat="server"
     UpdateMode="Conditional">
     <ContentTemplate>
     <asp:Label ID="Label2" runat="server"
     ForeColor="red" />
    ……………………………………………………..
    ………………………………………………………
    ……………………………………………………….
     </ContentTemplate>
     <Triggers>
     <asp:AsyncPostBackTrigger ControlID="Button1"
     EventName="Click" />
    </Triggers>
     </asp:UpdatePanel>
    Now we will create one sample application with updatepanels for that first create application and design your aspx page will be likes this
    <html xmlns="http://www.w3.org/1999/xhtml" >
     <head id="Head1" runat="server">
     <title>UpdatePanel Example in asp.net</title>
     </head>
     <body>
     <form id="form1" runat="server">
     <asp:ScriptManager ID="ScriptManager1" runat="server"/>
     <div>
     <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
     <ContentTemplate>
     <fieldset style="width:30%">
     <legend>Update Panel-1</legend>
     <asp:Label ID="lbl1" runat="server" ForeColor="green"/><br />
     <asp:Button ID="btnUpdate1" runat="server" Text="Update Both Panels" OnClick="btnUpdate1_Click" />
     <asp:Button ID="btnUpdate2" runat="server" Text="Update This Panel" OnClick="btnUpdate2_Click" />
     </fieldset>
     </ContentTemplate>
     </asp:UpdatePanel>
     <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
     <ContentTemplate>
     <fieldset style="width:30%">
     <legend>Update Panel-2</legend>
      <asp:Label ID="lbl2" runat="server" ForeColor="red" />
      </fieldset>
     </ContentTemplate>
     <Triggers>
     <asp:AsyncPostBackTrigger ControlID="btnUpdate1" EventName="Click" />
     </Triggers>
     </asp:UpdatePanel>
     </div>
     </form>
     </body>
    </html>
    If you observe above code in UpdatePanel2 I defined Triggers property with btnUpdate1. Here UpdatePanel2 content will update only whenever we click on btnUpdate1 because we defined UpdatePanel2 property UpdateMode="Conditional" and we set AsyncPostBackTrigger property with btnUpdate1
    Write following code in code behind
    C#.NET
    protected void btnUpdate1_Click(object sender, EventArgs e)
    {
    lbl1.Text = DateTime.Now.ToLongTimeString();
    lbl2.Text = DateTime.Now.ToLongTimeString();
    }
    protected void btnUpdate2_Click(object sender, EventArgs e)
    {
    lbl1.Text = DateTime.Now.ToLongTimeString();
    lbl2.Text = DateTime.Now.ToLongTimeString();
    }
    VB Code
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    End Sub
    Protected Sub btnUpdate1_Click(ByVal sender As Object, ByVal e As EventArgs)
    lbl1.Text = DateTime.Now.ToLongTimeString()
    lbl2.Text = DateTime.Now.ToLongTimeString()
    End Sub
    Protected Sub btnUpdate2_Click(ByVal sender As Object, ByVal e As EventArgs)
    lbl1.Text = DateTime.Now.ToLongTimeString()
    lbl2.Text = DateTime.Now.ToLongTimeString()
    End Sub


    LinK for GridView