背景:使用WCF实现跨进程普通函数调用,带回调的函数调用。
(转载请注明来源:cnblogs coder-fang)
- 解决方案示例图:
- 项目说明,WCFInterface(类库) 提供双方通信服务接口/契约,WCFService(类库) 实现相关服务接口,Hosting(控制台) 服务的宿主程序,WCFClient(控制台) 调用服务的客户端程序。
- 在WCFInterface中编写服务接口 :
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel; using System.Runtime.Serialization; namespace WCFInterface { [ServiceContract(CallbackContract = typeof(IPrintCallback))] public interface ITestServiceInterface { [OperationContract] int Add(int a, int b); [OperationContract(IsOneWay=true)] void findObjByName(string name); } [DataContract] public class MyObj { [DataMember] public int ID { get; set; } [DataMember] public string Name { get; set; } [DataMember] public int Age { get; set; } } }
- 在WCFInterface中编写回调接口: