我在 Windows窗体应用程序上托管了 WCF服务。 我有一个客户端应用程序(Windows窗体应用程序)。 我想将数据从客户端应用程序发送到托管WCF服务的Windows窗体应用程序。 这是我的代码: IMyService.cs
I have a WCF Service Hosted on Windows Forms Application. I have a Client Application(Windows forms application). I want to send data from Client application to the Windows Forms Application where WCF Service is hosted. Here is my code: IMyService.cs
[DataContract] public class DataMessage { [DataMember] public string Name { get; set; } } [ServiceContract] public interface IService1 { [OperationContract] string GetMessage(string name); [OperationContract] void BroadcastToClient(DataMessage eventData); }客户代码:
Client Code:
ServiceReference1.Service1Client client; DataMessage message = new DataMessage(); message.Name = textBox1.Text; client.BroadcastToClient(message);我应该在 Service.cs 中添加什么,以便将数据推送到托管的应用程序。 我尝试过: 服务。 cs:
What should I add in Service.cs, so that this pushes the data to the hosted Application. What I have tried: Service.cs:
public void BroadcastToClient(DataMessage eventData) { MessageBox.Show(eventData.Name); }我添加了Messagebox来查看它是否从客户端应用程序接收数据,以及工作正常... 现在我想将它发送到托管应用程序。
I have added Messagebox to just see whether its receiving the data from client Application, and its working fine... Now I want to send it to Hosted Application.
推荐答案我会建议从这里开始:双工服务 [ ^ ]。br /> 此CodeProject文章也很有用:双面WCF初学者指南 [ ^ ]。
这是我能找到的最简单的例子:带有命名管道的WCF示例 WCF教程 - 基本进程间通信 - Tech.pro [ ^ ] This is the simplest example I could find: WCF example with named pipes WCF Tutorial - Basic Interprocess Communication - Tech.pro[^]
更多推荐
如何将数据从WCF服务推送到客户端应用程序
发布评论