服务器客户架构.没有涉及IIS.这两个应用程序都是WinForm!
我在共享库中创建了以下接口:
[ServiceContract(SessionMode=SessionMode.required,CallbackContract=typeof(ClientInterface))] public interface RequestInterface { [OperationContract] void Subscribe(); [OperationContract] MyInterface GetInterface(); } public interface MyInterface { [DataMember] List<MySubInterface> SubClasses{get;} } public interface MySubInterface { [DataMember] int Value { get; } }
并在服务器上实现它们,如下所示:
public class RequestHandler : RequestInterface { private List<ClientInterface> iClients = new List<ClientInterface>(); public MyInterface GetInterface() { List<MySubInterface> tList = new List<MySubInterface>(); Form1.AddText("method invoked by:" + Thread.CurrentContext.ToString()); foreach (RealSubclass tClass in Form1.iClass.SubClasses) { tList.Add(new TransmissionSubclass(tClass.Value)); } TransmissionClass tTC = new TransmissionClass(tList); Form1.AddText("created:" + tTC); return tTC; } public void Subscribe() { Form1.AddText("subscribing:" + OperationContext.Current.GetCallbackChannel<ClientInterface>()); iClients.Add(OperationContext.Current.GetCallbackChannel<ClientInterface>()); fireClassEvent("halloWelt"); } }
在客户端上,我正在执行以下代码,尝试调用GetInterface()方法:
ClientClass tClass = new ClientClass(this); DuplexChannelFactory<RequestInterface> pipeFactory = new DuplexChannelFactory<RequestInterface>( tClass,new NetNamedPipeBinding(),new EndpointAddress( "net.pipe://localhost/Request")); RequestInterface pipeProxy = pipeFactory.CreateChannel(); //pipeProxy.Subscribe(); -- works like a charm MyInterface tInterface = pipeProxy.GetInterface(); // doesn't work fillListView(tInterface);
但是,当通过客户端逐步调试时,调试在标记的行处中断并且似乎退出此函数.
当我关闭应用程序的表单时,它只返回“逐步”模式.
另一方面,我可以从我的服务器上的日志输出中看到GetInterface()方法被执行.
TransmissionClass和TransmissionSubclass都在共享库中并实现MyInterface / MySubInterface
[DataContract] [Serializable] public class TransmissionClass : MyInterface { [DataMember] public List<MySubInterface> SubClasses{get;private set;} public TransmissionClass(List<MySubInterface> aList) { SubClasses = aList; } public override string ToString() { return "TransmissionClass,Count:" + SubClasses.Count; } }
服务器端的WCF初始化:
using (ServiceHost host = new ServiceHost( typeof(RequestHandler),new Uri[] { new Uri("net.pipe://localhost") })) { ServiceDebugBehavior tBehavior = new ServiceDebugBehavior(); if (null == tBehavior) { host.Description.Behaviors.Add(new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true }); } else if (!tBehavior.IncludeExceptionDetailInFaults) { tBehavior.IncludeExceptionDetailInFaults = true; } host.AddServiceEndpoint(typeof(RequestInterface),"Request"); host.open(); Application.Run(new Form1()); host.Close(); }
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。