wcf basics

WCF stands for "Windows Communication Foundation".

I have to learn WCF for some project requirement. When i started going through blogs and sites, I found it so boring and dry and complicated...and what not..i had slowly started losing interest in the technology itself..:(

But after reading the following post i understood the basics very quickly.

Very nice article..!!

So i have share that articles with you guys!

I think you guys too enjoy with this articles. cheers!

1. What is WCF?
http://blah.winsmarts.com/2008-4-What_is_WCF.aspx


2. Writing the Simple WCF Hello World Application - Service.
http://blah.winsmarts.com/2008-4-Writing_the_WCF_Hello_World_App.aspx


3. Writing the Simple WCF Hello World Application - Consumer (i.e Client)
http://blah.winsmarts.com/2008-4-Writing_your_first_WCF_client.aspx


4.Host a WCF Service in IIS 7 & Windows 2008 - The right way
http://blah.winsmarts.com/2008-4-Host_a_WCF_Service_in_IIS_7_-and-amp;_Windows_2008_-_The_right_way.aspx
 

How to Pass and Access a class into method in C#

public class Employee
    {
        public string EmpName{ get; set; }

        public string EmpAddress { get; set; }

    }

public class Welcome
    {
        public string WelcomeMethod(Employee emp)
        {
            return string.Format("Welcome {0} From {1}", emp.EmpName, emp.EmpAddress);
        }
    }

protected void Button1_Click(object sender, EventArgs e)
        {
                 Employee obj = new Employee();
                 obj. EmpName = TextBox1.Text;
                 obj.EmpAddress = TextBox2.Text;
                
                Welcome.WelcomeMethod(obj);
               
         }

Binding the Listview without page refresh in asp.net

<asp:ListView ID="lstInfo" runat="server" >
    <LayoutTemplate>
    </LayoutTemplate>
 <ItemTemplate>
</ItemTemplate>
 </asp:ListView>



protected void BindActiveRecord()
        {
            .DataSource = ds;
            lstInfo.DataBind();
        }
protected void Page_PreRender(object obj, EventArgs e)
        {
            BindActiveRecord();
         }

how to use Pager control in gridview without page refreshing

You can use EnableSortingAndPagingCallbacks = "true"

 For Example
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowSorting = "true"
 DataSourceID="SqlDataSource1" EnableSortingAndPagingCallbacks = "true">
 <Columns>
  <asp:BoundField DataField="FIRST_NAME" HeaderText="First Name"
                    SortExpression="FIRST_NAME" />
  <asp:BoundField DataField="LAST_NAME" HeaderText="Last Name"
                    SortExpression="LAST_NAME" />
  <asp:BoundField DataField="ADDRESS" HeaderText="Address"
                    SortExpression="ADDRESS" />
 </Columns>                 
</asp:GridView>

How to validate DropDownList In asp.net

<asp:DropDownList ID="ddlAttachment" runat="server">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="ddlAttachment" InitialValue="Choose One" ErrorMessage="Select One!" ></asp:RequiredFieldValidator>

how to use Pager control in listview without page refreshing

<asp:ListView ID="lstinfo" runat="server" OnPagePropertiesChanging="PropertiesChanging_lstinfoPager" >
    <LayoutTemplate>
<LayoutTemplate>
<ItemTemplate>
</ItemTemplate>
 </asp:listview>

<!-- Data Pager -->
    <div style="float:right;">
     <asp:DataPager ID="lstinfoPager" runat="server" PagedControlID="lstinfo"
    PageSize="5" >
    <Fields>
        <asp:NextPreviousPagerField ShowNextPageButton="false" ShowFirstPageButton="True" ButtonCssClass="pager"  />
        <asp:NumericPagerField CurrentPageLabelCssClass="current" NumericButtonCssClass="pager"  />
        <asp:NextPreviousPagerField ShowLastPageButton="True" ShowPreviousPageButton="False" ButtonCssClass="pager" />
    </Fields>
</asp:DataPager>



protected void PropertiesChanging_lstinfoPager(object sender, PagePropertiesChangingEventArgs e)
        {
            lstinfoPager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
            BindRecord();
        }

public void BindRecord()
{
       //Bind the listview
      lstinfo.DataSource = Your_datasource;
     lstinfo.DataBind();
}

How to get Enum Integer value in c#

public enum GetColor
    {
        Red = 1,
        Green = 2,
        Blue = 3,
    }

public void Button1_Click(object sender, EventArgs e)
{
        int colorvalue = Convert.ToInt16(GetColor.Green) ;
}

How to create jQuery DNNTabs in DotNetNuke

DotNetNuke has a Jquery DNNTabs Plugin. You can just copy and paste the following code in your .ascx control.

<script type="text/javascript">
    jQuery(function ($) {
        $('#tabs').dnnTabs();
    });
</script>


<div id="tabs" class="dnnForm dnnModuleSettings dnnClear">
    <ul class="dnnAdminTabNav dnnClear">
        <li><a href="#tab1">Tab1</a></li>
        <li><a href="#tab2">Tab2</a></li>
      
    </ul>
    <div id="tab1">
        Some content...
    </div>
    <div id="tab2">
        Success
    </div>       
   </div>

How to retrive the data from database based on datetime in asp.net

Your database have datetime field CreatedOn
DESC- Descending  Order
ASC - Ascending Order.

MSSQL Query

select * from tablename ORDER BY CONVERT(datetime, CreatedOn) DESC;

select * from tablename ORDER BY CONVERT(datetime, CreatedOn) ASC;


For cheking Condition

select * from tablename where Status = 1 ORDER BY CASE WHEN (CONVERT(date, ClosedDae) <= GetDate())THEN 1 ELSE 0  END ASC;

How to delete uploaded file from server using c#

you can write this code into your base class

using System.IO;

public static void DeleteExistFile(string name, string path)
    {
        if (name != null && File.Exists(path))
        {
            File.Delete(path);
        }
    }



You can write the following code In derived class button click event


Protected void Button1_Click(object sender, EventArgs e)
{
  string path = "~/Images/"+logo.jpg;
  BaseclassName.DeleteExistFile(filename,path);
}

(OR) If you want to single line code with out checking file exits or not, you have written this code


using System.IO;


Protected void Button1_Click(object sender, EventArgs e)
{
 File.Delete("~/Images/logo.jpg");
}

How to access sql connection using Method in ASP.NET

In Web.Config

 <connectionStrings>
     <add name="connection" connectionString="Data Source=.\SQLEXPRESS;Integrated Security=True;Initial Catalog=test;" providerName="System.Data.SqlClient" />
   </connectionStrings>



In DBClass.cs this is the class file 

using System.Data.SqlClient;
using System.Data;
using System.Web.Configuration;

//Get Connection String
    public static string connectionstring = WebConfigurationManager.ConnectionStrings["connection"].ConnectionString;

//Get Connection
    public static SqlConnection GetDbConnection()
    {
        return new SqlConnection(connectionstring);
    }


In Your aspx.cs

 SqlConnection con = DBClass.GetDbConnection();
SqlCommand cmd = new SqlCommand ("your sql command",con);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();



How to call connection string from Web.config In ASP.Net

 ASP.NET has a couple new ways to reference connection strings stored in the web.config or machine.config file.

<connectionStrings>
   <add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS; Initial Catelog="example" Integrated Security=true" providerName="System.Data.SqlClient"   />
</connectionStrings>

Easiest way to create connectiong string is to drag and drop one of your tables from the database to the page - connection string will be generated automatically. And you can call it like this:

using System.Configuration;

string conString = ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString;
SqlConnection conn = new SqlConnection(conString);
conn.Open();


the another method is using AppSettings,

In Web.config

<configuration>

  <appSettings>

     <add key="ConnectionString"

          value="server=localhost;uid=sa;pwd=;database=DBPerson" />

  </appSettings>

</configuration>



ASPX Code Behind (aspx.cs)

using System.Configuration;

string connectionString = (string )ConfigurationSettings.AppSettings["ConnectionString"];
        SqlConnection conn = new SqlConnection(conString);
        conn.Open();

Connection String In ASP.NET

The connectionStrings element specifies a collection of database connection strings, as name/value pairs, for ASP.NET applications and features.


In Web.Config

<connectionStrings>
   <add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=true;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
      providerName="System.Data.SqlClient"   />
</connectionStrings>
<connectionStrings>
   <add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS; Initial Catelog="example" Integrated Security=true" providerName="System.Data.SqlClient"   />
</connectionStrings>


One of the most misunderstood items, using ASP.Net, and some of the most asked questions, are about Connection Strings – the way in which you connect to the database. Any time you connect to a database, a Connection String is required, so it’s an integral part of .Net programming, whether it’s ASP.Net or WinForms programming. Of course, here, we’re addressing only ASP.Net programming, and mainly with SQL Server.
Each Connection String has several ‘sections’ in it. The basic form of the Connection String consists of:

ConnectionString=""


Your string can reside in different locations, including a DataSource Control (ASP.Net 2.0), in code, on the fly, and in the Web.Config file. Most likely, if you are using a particular string in multiple locations throughout your website, it will probably be best to store it in the Web.Config file. Then, any time, in your application, you need the connection string, the setting in the Web.Config file is referenced instead of the exact connection string. This way, if the connection string ever changes (and believe me, after years of doing this, I’m here to attest that it most likely WILL change at some time), then you will only need to change it in one place. How this is done, will be addressed, later on in this tutorial,

There are many sections of a connection string which are possible, but there are 3 basic sections which are absolutely required: The Server
The Database Name
The authentication
The Server can be notated in the Connection String several different ways, however, the most common usages are:

Data Source=YourServerGoesHere Server=YourServerGoesHere
In the above section, instead of ‘YourServerGoesHere’, you would put the address to the Server itself, in either a domain type of construction (like:MyServer.Com), or an IP address (like: 198.12.1987), Or ./SQLEXPRESS
So, at this point, using the Basic form from above, this would look like:

ConnectionString="Data Source=YourServerGoesHere" or ConnectionString="Server=YourServerGoesHere"
Naturally, the above, as mentioned before, can use ‘Server’ instead of ‘Data Source’
Next comes the Database section. It may be in 2 different forms:
Database=Northwind Intial Catalog=Northwind
The different sections in the Connection String need to be separated, so in order to do this, we use a semi-colon in between the different sections “;”. The entire connection string, then, will be surrounded by double-quotes("").

How to create a custom module in DNN 6

1. Download and install Visual Studio Starter Kit from the following link

http://dotnetnuke.codeplex.com/releases/view/78212#DownloadId=313768
 

2. Now you can open your DNN website Folder in visual studio 2010 by File -> Open Website -> select the website folder.
 

3. Right click your solution from solution explorer and select Add New Item -> choose - Visual c# -> DotNetNuke Dynamic Module and give Module Name. (for eg. My module Name is  NewsandEvents).



4.  Follow the Important Instruction in your visual studio. (i.e) In solution Explorer -> App_code/ModuleName Replace as Philip.NewsAndEvents and In DesktopModule Folder replace DesktopModule/ModuleName as Philip.NewsAndEvents.

5.In Web.config Add the follwing code

<codeSubDirectories>
               <add directoryName="Philip.NewsAndEvents" />
     </codeSubDirectories>


6. If you are working in visual studio 2010, you can also include the following code

<httpRuntime useFullyQualifiedRedirectUrl="true" maxRequestLength="2097152" requestLengthDiskThreshold="8192" requestValidationMode="2.0" />
 

7. Build the website and set start page as Default.aspx and run the website.

8. Login into super user account and choose Host -> SQL

9. Back to visual studio In DesktopModules -> NewsandEvents -> Double Click 01.00.00 SqlDataProvider


10. Edit -> SelectAll (or) ctrl+A, Select All the SqlScript and copy (ctrl+c).



11. Back to Web-Browser Paste your SqlScript Into Script Field.



12. Select Run as script and click Execute.

13. Now you can select Host -> Extensions
14. In extensions select Manage -> Create New Module

15. In create module from -> Select Control and Module folder field -> select Philip.NewsAndEvents, it will automatically bind EditNewsAndEvents.aspx in Resource field. Then give your ModuleName.
If you select Add test Page, it will create a new page for your module.


16. In Visual studio select DesktopModules/NewsAndEvents/NewsAndEvents.ascx , delete the existing code and add your own Asp.net code


 




17. NewsAndEvents.ascx.cs delete existing code and add Page_Load Event 

 



18. Build and execute the website. You have successfully create a DNN module.

What is Internet Information Services (IIS)

Internet Information Services (IIS) is a web server application and set of feature extension modules created by Microsoft for use with Microsoft Windows. IIS 7.5 supports HTTP, HTTPS, FTP, FTPS, SMTP and NNTP. It is an integral part of Windows Server family of products, as well as certain editions of Windows XP, Windows Vista and Windows 7. IIS is not turned on by default when Windows is installed.

Web Server

   It's a server used to communicate with Web Browsers as its clients and the communication protocol used in this case is HTTP (HyperText Transfer Protocol). This is why a Web Server is also called an HTTP Server.

How Web Server work?

As is the case with any client-server comunication, in this case also the client (i.e., the Web Browser) and the server (i.e., HTTP/Web Server) should be able to communicate with each other in a defined way. This pre-defined set of rules which form the basis of the communication are normally termed as a protocol and in this case the underlying protocol will be HTTP.

You have to enter the URL in your browser.The browser broke the URL into three parts:
  1.     The protocol ("http")
  2.     The server name ("www.example.com")
  3.     The file name ("home.html")
Step1

The browser communicated with a Domain name server to translate the server name "www.example.com" into an IP Address, this is the public IP Address. The browser then formed a connection to the server at this IP address.

Step 2

The browser sent a GET request to the server, asking for the file "http://www.example.com/home.html

Step 3

The server then sent the HTML text for the Web page to the browser.

Internet Information Services (IIS)

IIS has the following Properties

ApplicationPool

It is used to Isolate each application. We have run mor application in our single iis server. We can isolate them into their own AppPool. If one application craches, it doesn't impact the other application.

Port Number
Any server machine makes its services available to the Internet using numbered ports, one for each service that is available on the server.

For Example

Web server would typically be available on port 80, and the FTP server would be available on port 21.

Binding

We can bind the hostname,port no, and IP Address for each application.

Diffreence between Add website and Add Application in IIS


In Add websit, we need to give the unique port no

In Add Application, It takes the own website port no

 

DotNet Framework

.NET Framework is a software framework for Microsoft Windows operating systems. It includes a large library, and it supports several programming languages which allows language interoperability (each language can use code written in other languages). The .NET library is available to all the programming languages that .NET supports.