Click here to Skip to main content
15,900,818 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi. i am korea student
today i relly confused with this question.
this program is chat program with wcf+p2p

MSIL
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;

namespace WinChatForm
{
    [ServiceContract]
    interface IQuickP2PChat
    {
        [OperationContract(IsOneWay = true)]
        void Join(string nickname);
        [OperationContract(IsOneWay = true)]
        void SendMessage(string nickname, string msgbox);
        [OperationContract(IsOneWay = true)]
        void Leave(string nickname);
    }
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public partial class Main : Form, IQuickP2PChat
    {
        ServiceHost _host;
        IQuickP2PChat _proxy;
        string _nickname;
        ChannelFactory<IQuickP2PChat> factory;
        public Main()
        {
            InitializeComponent();
        }

        private void InitHost()
        {
            _host = new ServiceHost(this);
            _host.Open();
            //통신을 위한 클라이언트 프록시 구성
            factory = new ChannelFactory<IQuickP2PChat>("QuickP2PChatEndpoint");
            _proxy = factory.CreateChannel();
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (_proxy != null)
            {
                factory.Close();
            }
            if (_host != null && _host.State != CommunicationState.Closed)
            {
                _host.Close();
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                button1.Enabled = false;
            }
            else
            {
                button1.Enabled = true;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            InitHost();
            //채팅에 사용할 이름을 입력받는다.
            _nickname = textBox1.Text;
            _proxy.Join(_nickname);
            panel1.Enabled = true;
            textBox1.Text = "";
            textBox1.Enabled = false;
        }

        private void btnInputMsg_Click(object sender, EventArgs e)
        {
            string temp = txtInputMsg.Text + Environment.NewLine;
            _proxy.SendMessage(_nickname,temp);
            txtInputMsg.Clear();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            _proxy.Leave(_nickname);
            this.Close();
        }

        void IQuickP2PChat.Join(string nickname)
        {
            txtShow.Text  += nickname + "Joined!!" + Environment.NewLine;
            lstUser.Items.Add(nickname);
        }

        void IQuickP2PChat.SendMessage(string nickname, string msgbox)
        {
            txtShow.Text = "[" + nickname + "]" + " " + msgbox;
        }

        void IQuickP2PChat.Leave(string nickname)
        {
            txtShow.Text = nickname + "Leaved!!" + Environment.NewLine;
            lstUser.Items.Remove(nickname);
        }
    }
}


app.config

XML
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <netPeerTcpBinding>
        <binding  name="BindingUnsecure">
          <security mode="None"/>
          <resolver mode="Pnrp"/>
        </binding>
      </netPeerTcpBinding>
    </bindings>
    <services>
      <service name="WinChatForm.Main">
        <host>
          <baseAddresses>
            <add baseAddress="net.p2p://QuickP2PChat"/>
          </baseAddresses>
        </host>
        <endpoint
            contract="WinChatForm.IQuickP2PChat"
            address=""
            binding="netPeerTcpBinding"
            bindingConfiguration="BindingUnsecure"
          />
      </service>
    </services>
    <client>
      <endpoint
          name="QuickP2PChatEndpoint"
          address="net.p2p://QuickP2PChatChat"
          binding="netPeerTcpBinding"
          bindingConfiguration="BindingUnsecure"
          contract="WinChatForm.IQuickP2PChat"
      />
    </client>
  </system.serviceModel>
</configuration>



i relly need to this program working well....
someone help me? X|

1st fix version : i got some code at msdn the original form
version working well, but my custom version does not work
no compile error and exe error
Posted
Updated 6-Jun-10 19:01pm
v4
Comments
DaveAuld 6-Jun-10 9:37am    
What are you confused with? where are you stuck? dumping code and making a general statement won't help..............

As a student, you should know how to do research. Instead of grabbing random code, you should research what you're trying to do, work on your code, debug it, understand it, and when you ask for help, show us a specific piece of code, with specific text explaining which bit does not do what you expect, what it does, and what you've done to try to fix it.
 
Share this answer
 
Comments
sungju park 7-Jun-10 0:55am    
thank you for answer my question. this program's original version is console app. it works good, but i try to fix winform program it does not work. i try to fix this program 2days day and night but it doesn't work... and i can't write english very well so i put comments in the program only korean;;...
You should call InitHost at the startup; that is in the constructor of the form or in Form_Load.
I wish this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900