我遇到了抛出上述异常的问题。我在代码中创建了一个服务器和一个客户端,用于进程间通信。
服务器看起来像这样:
[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 上)调用方法时,都会出现上述异常。
我究竟做错了什么?非常感谢任何帮助。
标记