[英]How to call a method in WPF application from a WCF Service hosted by the same WPF application?
我已经创建了WPF应用程序中托管的WCF服务。 一切正常。 我的客户可以毫无问题地访问WCF服务。
现在,当客户端调用我的服务中的方法时,例如:SetData(MyDataObject data),我希望该方法将“数据”对象发送回WPF主机进行处理。
我该如何接线呢???
我的服务托管在WPF应用程序中:
host = new ServiceHost(typeof(WCFTestService.Service1), new Uri("http://localhost:8733/WCFTestService/"));
// Service host is opened on the UI thread
host.AddServiceEndpoint(typeof(WCFTestService.IService1), new BasicHttpBinding(), "");
// Enable metadata exchange
ServiceMetadataBehavior smb = new ServiceMetadataBehavior() { HttpGetEnabled = true };
host.Description.Behaviors.Add(smb);
// Enable exeption details
ServiceDebugBehavior sdb = host.Description.Behaviors.Find<ServiceDebugBehavior>();
sdb.IncludeExceptionDetailInFaults = true;
host.Open();
我的WCF服务方法:
public bool SetData(MyDataObject data)
{
//HOW DO I get MyDataObject to the WPF Host???
// something like: host.UpdateData(data) <-- callback method???
return true;
}
我偏离了这个问题,但是表示层和服务层如此紧密地耦合是不是有一个特殊的原因呢? 我认为您可以将MyDataObject的内容添加到您创建的数据传输对象中,或者持久保存MyDataObject(也许是暂时的),然后让WPF应用程序/主机通过同一wcf服务公开的方法调用对其进行访问。 我可能会用您提供的数据来做到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.