【发布时间】:2014-08-10 14:50:50
【问题描述】:
我创建了一个托管在 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;
}
【问题讨论】: