• Home
  • About
  • BestBloggingIdeas
  • DotNetLearningSource
  • FORUM
  • Joblinks
  • Latest News
  • Policy
  • POSTS
  • SimplySqlServer.Com && SimplyAspDotNet.Com
  • Sitemap

Join Ours Forum

Asp.Net,C#,Ajax,Sql server,silverlight,Javascript codes exambles articles,Programming exambles

RSS Feed
  • Bounty Huge Roll [Amazon Frustration-Free Packaging]
  • XML Introduction to XML VHS Video Training, 1 hr., 32 minutes.
  • The Basic Overview of Windows Mobile Development Asp.Net C#
  • Overview of Sql server extended properties Asp.Net C#
  • How to Use Sql Server Extended properties using visual studio Asp.Net C#
  • Adobe Dreamweaver Templates Accelerate Web Development
  • Top Tips for Web Design Projects
  • How to Achieve a Good Web Design Structure
  • To Use Or Not To Use Website Templates
  • Five Tips to a Successful Website
  • Top 10 Articles,


    Silverlight Datagrid Select Update Delete Insert Asp.Net C#

    Differences Similarities Benefits Between Typed Datasets and Untyped Datasets asp.net c#

    Linq to Sql Introduction Entities Ado.Net C# SqlClasses Attributes Linq Mapping

    Linq Programming/How Linq Works?/Linq Implementation In Asp.Net C# Ado.Net

    Performing Developing Using Investigating Asp.Net 2.0 Ajax Application Development Asp.Net C#

    Hosting/Install Wcf Services in a Windows Service Asp.Net C#

    Connecting Silverlight to Wcf Asp.Net C#

    Silverlight Data Grid Data Binding WCF Asp.Net C#

    Invoking/Accessing/Calling WCF Service Without Adding/Creating Proxy/Reference Asp.Net C#

    Performing Doing Creating Insert Update Delete sql data Using Linq Database Asp.Net C#

    Creating Socket Programming Using WCF NetTcpBinding and NetNamedPipeBinding

    Posted by on July 3, 2010 Leave a comment (3) Go to comments

    Introduction:
    In this article i am going to explain about how to use nettcpbinding and netnamed
    pipebinding in WCF programming.

    Main:

    Bindings are the mechanism by which communication details are specified to make connecting
    to a service’s WCF endpoint,

    NetTcpBinding :- Provides a secure and reliable binding environment for .Net to .Net
    cross machine communication.It Uses TCP protocol and provides full support for SOAP
    security,transaction and reliability.

    NetNamedPipeBinding :- The NetNamedPipeBinding provides a secure and reliable binding
    environment for cross-process (same machine) communication. It uses the NamedPipe protocol
    and provides full support for SOAP security, transactions, and reliability.

    Demonstration:
    1.Creating WCF Service Library,

    Goto Project –> New Project –> WCF –> Select WCF Library and named as NetTcpLibrary,

    wcflib2

    Paste the below Code,

    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
     
     
    namespace NetTcpLibarary
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
        [ServiceContract]
        public interface INetTcpService
        {
            [OperationContract]
            DataSet ReturnEmpDetails(int EmpId);
        }
     
        // Use a data contract as illustrated in the sample below to add composite types to service operations
     
        public class NetcpService : INetTcpService
        {
     
            DataSet INetTcpService.ReturnEmpDetails(int EmpId)
            {
                SqlConnection conn = new SqlConnection("Data Source=CHANDRU-PC;Initial Catalog=master;Integrated Security=True");
                conn.Open();
                SqlCommand cmd = new SqlCommand(string.Format("Select firstname,lastname,deptname,Manager from Emp where empid = {0}", EmpId),conn);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                cmd.ExecuteNonQuery();
                DataSet ds = new DataSet();
                da.Fill(ds);
                return ds;          
     
            }   
     
        }
     
    }

    2.Host the WCF service,

    Create one windows application and named it HostingNetTcp,
    Refer the Service Library we created,(Goto Add Reference and refer NetTcpLibrary.dll)

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.ServiceModel;
    using System.ServiceModel.Description;
     
    using NetTcpLibarary;
     
     
    namespace HostingNetTcp
    {
        public partial class Form1 : Form
        {
            ServiceHost local_sh = null;
            public Form1()
            {
                InitializeComponent();
            }
     
            private void Form1_Load(object sender, EventArgs e)
            {
                Uri local_Namedpipe = new Uri("net.pipe://localhost/NetNamedPipeBinding");
                Uri local_tcp = new Uri("net.tcp://localhost:8000/TcpBinding");
     
                local_sh = new ServiceHost(typeof(NetcpService), local_tcp, local_Namedpipe);
     
                NetNamedPipeBinding local_pb = new NetNamedPipeBinding();
                NetTcpBinding local_tcpb = new NetTcpBinding();
     
                ServiceMetadataBehavior local_mbehave = new ServiceMetadataBehavior();
                local_sh.Description.Behaviors.Add(local_mbehave);
                local_sh.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
                local_sh.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexNamedPipeBinding(), "mex");
                local_sh.AddServiceEndpoint(typeof(INetTcpService), local_pb, local_Namedpipe);
                local_sh.AddServiceEndpoint(typeof(INetTcpService), local_tcpb, local_tcp);
     
                local_sh.Open();
     
                label1.Text = "Service Running";
     
            }
            private void Form1_FormClosing(object sender, FormClosingEventArgs e)
            {
                local_sh.Close();
            }
        }
    }

    hosting

    3.Create a WCF Client,

    Make Host service application is running,

    Refer the url’s we created in hosting application,

    wcfreference12

    wcfreference21

    Create One Windows application and named as NetTcpBindingClient,

    using System;
    using System.Data;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
     
    namespace NetTcpBindingClient
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
     
            private void Form1_Load(object sender, EventArgs e)
            {
     
            }
     
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
     
            }
     
            private void button1_Click(object sender, EventArgs e)
            {
                TCP.NetTcpServiceClient objclient = new TCP.NetTcpServiceClient("NetTcpBinding_INetTcpService");
                DataSet ds = objclient.ReturnEmpDetails(Convert.ToInt32(textBox1.Text));
                if (ds.Tables[0].Rows.Count > 0)
                {
                    label2.Text = ds.Tables[0].Rows[0].ItemArray[0].ToString();
                    label3.Text = ds.Tables[0].Rows[0].ItemArray[1].ToString();
                    label4.Text = ds.Tables[0].Rows[0].ItemArray[2].ToString();
                    label5.Text = ds.Tables[0].Rows[0].ItemArray[3].ToString();
                }
            }
     
            private void button2_Click(object sender, EventArgs e)
            {
                NetPipe.NetTcpServiceClient objNetClient = new NetPipe.NetTcpServiceClient("NetTcpBinding_INetPipeService");
                DataSet Netds = objNetClient.ReturnEmpDetails(Convert.ToInt32(textBox1.Text));
                if (Netds.Tables[0].Rows.Count > 0)
                {
                    label2.Text = Netds.Tables[0].Rows[0].ItemArray[0].ToString();
                    label3.Text = Netds.Tables[0].Rows[0].ItemArray[1].ToString();
                    label4.Text = Netds.Tables[0].Rows[0].ItemArray[2].ToString();
                    label5.Text = Netds.Tables[0].Rows[0].ItemArray[3].ToString();
                }
            }
        }
    }

    wcfresult

    Conclusion:
    Hope this helps,
    Happy Coding.

    WCF
    ← WPF Programming-All in one Actions
    Using message contracts in wcf/wcf message contracts programming →

    Learn Easily Using Video Tutorials


    How to choose the right Java IDE – explained Eclipse NetBeans BlueJ

    Developing/Creating/Performing/Configuring Java Applications Using Eclipse IDE

    Step By Step Guide for Download/Install Configure Eclipse IDE for Java

    Editing data with the GridView control Asp.Net C#

    Registering/Configuring Web Controls globally in web.config file asp.net c#

    Registering/Configuring Web Controls globally in web.config file asp.net c#

    Best way to prepare asp.net Interview - Success Stories

    Download Important Questions and PPT's:

    Sql Server Important Questions Online free download

    Dotnet Important Questions Online free download

    Exploring Linq to Sql Process Flow

    Learn how to perform silverlight programming

    Learn OOPs concepts in better and well manner

    Learn Ajax in better and well manner

    Leave a comment

    3 Comments.

    1. Nasfer August 14, 2010 at 3:20 am

      I would like to exchange links with your site netprogramminghelp.com
      Is this possible?

    2. Colby Tonnesen August 23, 2010 at 4:11 pm

      Thank you for another great article. Where else could anyone get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information.

    3. Mike November 29, 2010 at 11:10 pm

      I am very new to wcf and the .net enviroment. Our WCF person has recently left our company and I have inherited his projects. I don’t want to offend anyone by asking this (and I know this is a sore subject for many programmers) but can this be coverted into vb code easily? We have several services written already in this and I am having to make updates to them. It is for ease of reading on my part….

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    *

    *


    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    Enter your email address:

    Delivered by FeedBurner

    • Recent Posts

      • Bounty Huge Roll [Amazon Frustration-Free Packaging]
      • XML Introduction to XML VHS Video Training, 1 hr., 32 minutes.
      • The Basic Overview of Windows Mobile Development Asp.Net C#
      • Overview of Sql server extended properties Asp.Net C#
      • How to Use Sql Server Extended properties using visual studio Asp.Net C#
    • Search by Tags!

      Application AspNet Basic between Black Bluetooth Build Business Collection Consultants Design Development Downloading effective Excel Experts Generics Implement Installing Interview Logic Management Microsoft Minutes Object Outlook Professional Programmer Programming Project Projects Questions Ready Select Server Services Silverlight Source Strings Studio Through using Visual Website Wordpress
    • Archives

      • August 2011
      • June 2011
      • May 2011
      • April 2011
      • March 2011
      • February 2011
      • December 2010
      • November 2010
      • October 2010
      • September 2010
      • August 2010
      • July 2010
      • June 2010
      • May 2010
      • April 2010
      • March 2010
      • February 2010
      • January 2010
      • December 2009
      • November 2009
      • October 2009
      • September 2009

    Copyright © 2012 NetProgrammingHelp.com

    Δ Top