Saturday, April 5, 2014

Dependency Property in WPF

Dependency properties have more uses in WPF and having advanced features. WPF Classes used more properties rather than methods.
Before going to Dependency properties in WPF, we need to understand our normal DotNet Properties.

Dot Net Properties
Class A
{
private int  _myvalue;


public int MYVALUE
{
get{return _myvalue;}
set{ _myvalue=Value;}
}

}

A property must associated with private field in class and represent that field to other classes. This field is backing field.
backing field nothing but private variable which holds the property value.

Assign value
When ever value get assigned to the property, value is passed to Set accessor reflect value to backing field.
Read Value
When ever value get read from the property, Get accessor just return the value from backing field

Dot net property can be easily assigned and read directly from private variables whereas WPF Dependency properties value is resolved dynamically
When calling GETVALUE() method that is inherited from Dependency Object.

WPF -Dependency Properties


Advantages
Reduce Memory Usage:
      If we set value to parent Control it will easily reflect to all child controls. modified properties present in the instance. The Default value stored once with dependency property.
Value Inheritance:
   Dependency property value is resolved using value resolution strategy. if no local value being set, the dependency property will travel from top to bottom until find its value.
Change Notification:
      Dependency properties having new feature built in notification whenever a value modify it will notify the changes. By registering a callback data in the mechanism. Used in DataBinding techniques.

Features
Value of  dependency property  is not stored in field of object, but it will stored in dictionary of keys and value will provided by the base class Dependency Object.

VALUE RESOLUTION STRATEGY


Example
XAML File which set FontWeignt bold it will reflect to all child controls unless explicitly modification/Changes in the controls.

<Window X:Class="Inherit.Font.Window1"....>
<GroupBox FontWeight="Bold">
<GroupBox.Header>
Buttons
</GroupBox.Header>
</GroupBox>
<StackPanel>
<Button FontWeight="Medium">Update</Button>
<Button>Reset</Button>
</StackPanel>
</Window>
Sample Dependency property

// Dependency Property
public static readonly DependencyProperty CurrentTimeProperty = DependencyProperty.Register( "CurrentTime", typeof(DateTime), typeof(MyClockControl), new FrameworkPropertyMetadata(DateTime.Now));

// .NET Property wrapper
public DateTime CurrentTime
{
get { return (DateTime)GetValue(CurrentTimeProperty); }
set { SetValue(CurrentTimeProperty, value); }
}

Saturday, February 1, 2014

How to Create Web Service using C# (For Beginners)


 Creating Web Service in C# Step by Step manner (Use full for freshers)
  •   Create new project in Visual studio framework



  • Choose the visual studio 3.5 framework using C# programming language in Web Application Template Choose ASP.NET Web Service Application create new web service project.



















  • After Opening the solution the default web method "HELLO WORLD ()" in the Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace WebService1
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

              
    }
}

  • Created custom method for getting input parameter in the below web method. In this below method i get  input string parameter.  
          [WebMethod]
        public string Welcome(string name)
        {
            return string.Format("Welcome {0} to Tutorial Web Service", name);
        }


  • After executing the Web Service Application the all methods displayed in the screen


  • Input Parameter method invoke Operation

  • After invoke Operation result of the web method the result will appear as below,




















I hope the above article will meet the expectation for simple Creating Web Service.