如何将数据从WCF服务推送到客户端应用程序

编程入门 行业动态 更新时间:2024-10-09 03:27:11
本文介绍了如何将数据从WCF服务推送到客户端应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在 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初学者指南 [ ^ ]。
-SA
I would advise to start here: Duplex Services[^]. This CodeProject article can also be useful: A Beginner's Guide to Duplex WCF[^].
—SA

这是我能找到的最简单的例子:带有命名管道的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服务推送到客户端应用程序

本文发布于:2023-11-16 14:45:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1605228.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   应用程序   客户端   数据   WCF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!