我遇到了抛出上述异常的问题。我已经在代码中创建了一个服务器和一个客户端进行进程间通信。
服务器如下所示:
[ServiceContract]
public interface INotifyFullScreen
{
[OperationContract]
void NotifyAndonFullScreen();
}
public class NotifyFullScreen : INotifyFullScreen
{
public void NotifyAndonFullScreen()
{
MainWindow.CurrentInstance.NotifyFullScreen();
}
}
//...NotifyFullScreen() implemented in another class
using (
var host = new ServiceHost(
typeof(NotifyFullScreen), new[] { new Uri("net.pipe://localhost/NotifyFullScreen") }))
{
host.AddServiceEndpoint(
typeof(INotifyFullScreen), new NetNamedPipeBinding(), "NotifyFullScreen");
host.Open();
app = new App();
app.Run();
host.Close();
}
......客户端看起来像这样:
[ServiceContract]
public interface INotifyFullScreen
{
[OperationContract]
void NotifyAndonFullScreen();
}
// ..
var pipeFactory = new ChannelFactory<INotifyFullScreen>(new NetNamedPipeBinding(), new
EndpointAddress("net.pipe://localhost/NotifyFullScreen"));
var notifyProxy = pipeFactory.CreateChannel();
try
{
notifyProxy.NotifyAndonFullScreen();
pipeFactory.Close();
}
catch (Exception ex)
{
MessageBox.Show("Exception!");
EventTrace.Default.LogException(ex);
}
每当我尝试在客户端上调用一个方法(在notifyProxy上)时,我都会得到上述异常。
我做错了什么?非常感谢任何帮助。
标记