Все еще борется с серверной стороной моего приложения wcf. :)
Как видно из кода, я пытаюсь вызвать событие всякий раз, когда клиент делает StartConnection . Но почему-то кажется, что я не могу создать экземпляр серверного объекта правильно, так как это дает мне эту ошибку 3.
Пожалуйста, предложите, что было бы правильным способом сделать это? Спасибо! :)
namespace server2
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
myServer.eventHappened += new EventHandler(eventFunction);
// 'server2.IfaceClient2Server' does not contain a definition for 'eventHappened' and no extension method 'eventHappened' accepting a first argument of type 'server2.IfaceClient2Server' could be found (are you missing a using directive or an assembly reference?)
}
IfaceClient2Server myServer = new ServerClass();
// The type or namespace name 'eventCaller' could not be found (are you missing a using directive or an assembly reference?)
void eventFunction(object sender, EventArgs e)
{
label1.Text = myServer.clientName;
// 'server2.IfaceClient2Server' does not contain a definition for 'clientName' and no extension method 'clientName' accepting a first argument of type 'server2.IfaceClient2Server' could be found (are you missing a using directive or an assembly reference?)
}
}
class ServerClass : IfaceClient2Server
{
public event EventHandler eventHappened;
//IfaceServer2Client callback = OperationContext.Current.GetCallbackChannel<IfaceServer2Client>();
public string clientName;
public void StartConnection(string name)
{
clientName = name;
eventHappened(this, new EventArgs());
MessageBox.Show(clientName + " has connected!");
}
public void Message_Cleint2Server(string msg)
{
}
public void Message2Client(string msg)
{
}
}
[ServiceContract(Namespace = "server", CallbackContract = typeof(IfaceServer2Client), SessionMode = SessionMode.Required)]
public interface IfaceClient2Server ///// what comes from the client to the server.
{
[OperationContract(IsOneWay = true)]
void StartConnection(string clientName);
[OperationContract(IsOneWay = true)]
void Message_Cleint2Server(string msg);
}
public interface IfaceServer2Client ///// what goes from the sertver, to the client.
{
[OperationContract(IsOneWay = true)]
void AcceptConnection();
[OperationContract(IsOneWay = true)]
void RejectConnection();
[OperationContract(IsOneWay = true)]
void Message_Server2Client(string msg);
}
}