MSN

Arkadaş listemizi gösterecek bir listBox
Sohbet yazılarını gösterecek bir listBox gerekli
Database tanımladık.
Service oluşturuyoruz | WCF Application
Bize liste gerekiyor. Önce veritabanını çekiyoruz.
Add New Item | Linq to SQL
Veritabanını bağladık. Kişi ve sohbet tabloları gerekiyor. Kaydedip çıktık.
Interface
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace MSNServis
{
// 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]
publicinterfaceIService1
    {
        [OperationContract]
List<Kisiler> KisiListesi();
        [OperationContract]
Kisiler KisiListesiDogrulama(string nick, string ad);
         [OperationContract]
List<Sohbet> SohbetListesi(int gonderenId, int AlanId);
         [OperationContract]
void SohbetEkle(int gonderenId, int alanId, string metin);
         [OperationContract]
string ResimGetir(int alanId);
// TODO: Add your service operations here
    }
// Use a data contract as illustrated in the sample below to add composite types to service operations.
}
Service1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace MSNServis
{
// NOTE: You can use the “Rename” command on the “Refactor” menu to change the class name “Service1” in code, svc and config file together.
publicclassService1 : IService1
    {  MsnDataContext data=newMsnDataContext ();
publicList<Kisiler> KisiListesi()
        {
var sonuc = from p in data.Kisilers
select p;
return sonuc.ToList();
        }
publicList<Sohbet> SohbetListesi(int gonderenId,int AlanId)
        {
var sonuc = from p in data.Sohbets
where
                        (p.GonderenId == gonderenId && p.AlanId == AlanId) ||
                        (p.GonderenId == AlanId && p.AlanId == gonderenId)
select p;
return sonuc.ToList();
        }
publicvoid SohbetEkle(int gonderenId, int alanId, string metin)
        {
Sohbet bilgi = newSohbet()
            {
                GonderenId = gonderenId,
                AlanId = alanId,
                Metin = metin,
                Gtarih = DateTime.Now,
                Durum = 0
            };
            data.Sohbets.InsertOnSubmit(bilgi);
            data.SubmitChanges();
        }
publicKisiler KisiListesiDogrulama(string nick, string ad)
        {
var sonuc = (from p in data.Kisilers
where p.Nick == nick && p.Ad == ad
select p).First();
return sonuc;
        }
publicstring ResimGetir(int alanId)
        {
var sonuc = (from p in data.Kisilers
where p.ID==alanId
select p.Resim).First();
return sonuc;
        }
    }
}
Webconfig
<?xmlversion=1.0?>
<configuration>
<connectionStrings>
<addname=MSNConnectionStringconnectionString=Data Source=.;Initial Catalog=MSN;Integrated Security=True
providerName=System.Data.SqlClient />
</connectionStrings>
<system.web>
<compilationdebug=truetargetFramework=4.0 />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!– To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment –>
<serviceMetadatahttpGetEnabled=true/>
<!– To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information –>
<serviceDebugincludeExceptionDetailInFaults=false/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironmentmultipleSiteBindingsEnabled=true />
</system.serviceModel>
<system.webServer>
<modulesrunAllManagedModulesForAllRequests=true/>
</system.webServer>
</configuration>
MSN Uygulama dosyasındayız
Sohbet.cs
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;
namespace MSN
{
publicpartialclassSohbet : Form
    {
public Sohbet(int alanId,int gonderenId,Uri resim)
        {
            InitializeComponent();
            aId = alanId;
            gId = gonderenId;
           webBrowser2.Url= resim;
        }
int aId = 0;
int gId = 0;
        MsnClient.Service1Client data = new MsnClient.Service1Client();
privatevoid Sohbet_Load(object sender, EventArgs e)
        {
            webBrowser1.Url=newUri (data.ResimGetir(aId));
            timer1.Enabled = true;
            SohbetListe();
        }
privatevoid SohbetListe()
        {
            MsnClient.Sohbet[] bilgi = data.SohbetListesi(gId, aId);
            listBox1.Items.Clear();
foreach (var item in bilgi)
            {
                listBox1.Items.Add(“———–“ + item.Gtarih.ToString() + “————“);
                listBox1.Items.Add(“—————“ + item.GonderenId.ToString() + “:—————-“);
                listBox1.Items.Add(item.Metin);
            }
        }
privatevoid timer1_Tick(object sender, EventArgs e)
        {
            SohbetListe();
        }
privatevoid btnGonder_Click(object sender, EventArgs e)
        {
            data.SohbetEkle(gId,aId,textBox1.Text);
            SohbetListe();
        }
privatevoid textBox1_TextChanged(object sender, EventArgs e)
        {
        }
privatevoid textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
if (e.KeyChar == 13)
            {
                btnGonder_Click(null,null);
            }
        }
    }
}
Form1.cs
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;
namespace MSN
{
publicpartialclassForm1 : Form
    {
public Form1()
        {
            InitializeComponent();
        }
        MsnClient.Service1Client data = new MsnClient.Service1Client();
privatevoid Form1_Load(object sender, EventArgs e)
        {
        }
privatevoid listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
        }
privatevoid listBox1_DoubleClick(object sender, EventArgs e)
        {
if (Id != 0)
            {
Sohbet f = newSohbet(Convert.ToInt32(listBox1.SelectedValue), Id, webBrowser1.Url);
                f.Show();
            }
else
            {
MessageBox.Show(“Hatalı Bilgi Girisi”);
            }
        }
publicstaticint Id = 0;
privatevoid button1_Click(object sender, EventArgs e)
        {
try
            {
                 MsnClient.Kisiler kisi=data.KisiListesiDogrulama(textBox1.Text, textBox2.Text);
                 Id = kisi.ID;
                panel1.Visible = false;
                webBrowser1.Url = newUri(kisi.Resim);
                webBrowser1.Visible = true;
            }
catch
            {
                Id = 0;
            }
if (Id == 0)
            {
MessageBox.Show(“Hatalı Bilgi Girisi”);
            }
else
            {
                listBox1.DataSource = data.KisiListesi();
                listBox1.DisplayMember = “Nick”;
                listBox1.ValueMember = “ID”;
            }
        }
privatevoid webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
        }
    }
}

Ramazan CESUR