如何使用C#中的Web服务定期从客户端向服务器发送消息,以及如何往返发送消息? [英] how to send messages at regular intervals from the client to the server and back forth using web services in C#?

查看:60
本文介绍了如何使用C#中的Web服务定期从客户端向服务器发送消息,以及如何往返发送消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地计算机上托管了一个Web服务,并将其用作Web服务器,并在客户端计算机上使用了Web服务.

现在,当客户端使用Web服务时,Web服务器应该在固定的时间间隔内从客户端收到有关客户端正在使用该服务的通知,并且服务器还应该发送确认已收到通知的确认..

I have a web service hosted on my local machine which I have made as a web server and a client machine that consumes the web service.

Now when the web service is consumed by the client the web server should get notifications from the client at regular interval of time that the client is using the service and the server should also send a acknowedgement that it got the notification..

How should I implement this?

推荐答案

Erhm ...
你想要什么?在标题中,您说您希望服务器将消息发送到客户端,而在您的问题中,您说客户端应将消息发送到服务器.
无论如何,没有客户端的请求就不可能从Web服务向客户端发送消息,您将需要实现与Web服务不同的技术.如果希望客户端定期将消息发送到Web服务,则只需使用 ^ ].

祝你好运,
Eduard
Erhm...
What do you want? In the header you say you want the server to send messages to the client, and in your question you say the client should send messages to the server¿?

Anyway, sending messages from a web service to a client is impossible without a client''s request, you''ll need to implement a different technique than a webservice. If you want the client to regularly send messages to the webservice, just use a Timer[^].

Good luck,
Eduard


您可以使用System.Net.Mail将邮件发送到您的帐户,或放置一个将写入日志文件的功能.然后将其插入到您的特定服务代码块中.

You can use the the System.Net.Mail to send mail to your account, or put a function that will write into your log file. Then insert it to your specific service codeblock.

public void SendMail(string from, string to, string subject, string body) {
     MailMessage message = new MailMessage { Subject = subject, Body = body };
     SmtpClient smtp = new SmtpClient();
     smtp.Send(message);
}


这篇关于如何使用C#中的Web服务定期从客户端向服务器发送消息,以及如何往返发送消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆