周星驰真的会功夫吗:C#编写的聊天程序调用dll出错

来源:百度文库 编辑:神马品牌网 时间:2024/05/11 18:50:05
protected void nickname_btn_Click(object sender,System.EventArgs e)
{
try{

//coding manipulation starts here…
if(!connected)
{
int listeningChannel=0;
//Create and register a channel to communicate to the server
//The Client will use the port passed in as args to listen for callbacks
channel=new HttpChannel(listeningChannel);
ChannelServices.RegisterChannel(channel);

//Creat an instance on the remote server and call a method remotely
topic=(Topic)Activator.GetObject(typeof(Topic),//type to create
"http://localhost:1099/Topic.soap"//URI
);

username=nickname_txtbox.Text;
//add the user to the server
bool check=topic.addUser(nickname_txtbox.Text,ref textBox1,ref listBox1);

if(!check)
{

//if server rejected user then do clean up
connected=false;
btnListname.Enabled=false;
nickname_txtbox.Enabled=true;
nickname_btn.Enabled=true;
ChannelServices.UnregisterChannel(channel);
topic=null;
nickname_txtbox.Text="";
}
else{
//set up variables and buttons
connected=true;
btnListname.Enabled=true;
nickname_txtbox.Enabled=false;
nickname_btn.Enabled=false;
this.Text="Client"+username+"Connected";
}
}

}
catch(Exception ed)
{
MessageBox.Show(this,"Exception occured"+ed.ToString());
}

}

protected void btnListname_Click(object sender,System.EventArgs e)
{
//call the method to quit rom server
quitclient();
}
protected void button1_Click(object sender,System.EventArgs e)
{
//send the message to everyone
if(textBox2.Text!=""){
topic.sendMessage(username+":"+textBox2.Text);
textBox2.Text="";
}
}

}
}