且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用C#中的Web服务定期从客户端向服务器发送消息,以及如何往返发送消息?

更新时间:2022-01-05 21:40:26

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);
}