简体   繁体   English

从Windows窗体应用程序中侦听WCF服务

[英]Listening to a WCF service from a Windows Forms Application

I have been tasked with writing some functionality into my companies web application (written in C# and ASP.NET). 我的任务是将一些功能写入我的公司Web应用程序(用C#和ASP.NET编写)。

Part of the web application allows customers to raise support tickets via the website. 部分Web应用程序允许客户通过网站提出支持服务单。 These are posted to the server through a WCF web service. 这些通过WCF Web服务发布到服务器。

What the company wants is a mechanism, whereby when a customer raises a support ticket, technicians are notified by a windows forms application that will sit in the task tray and show balloon tips saying there is a new ticket. 公司想要的是一种机制,当客户提出支持票时,技术人员会通过Windows窗体应用程序通知任务托盘并显示气球提示,说明有新票。

The server that hosts the web application (and WCF services) are on different domains to the Technician's machines, and therefore I believe that this mechanism will require some kind of REST service which posts a message to all listening Windows Forms clients. 承载Web应用程序(和WCF服务)的服务器位于与技术人员的计算机不同的域上,因此我认为此机制将需要某种REST服务,该服务将消息发布到所有侦听的Windows窗体客户端。

I've trawled through a lot of articles about REST services, listening to WCF...without much progress! 我已经浏览了很多关于REST服务的文章,听WCF ...没有太大进展!

My questions are: 我的问题是:

  • What would be considered an acceptable, modern approach? 什么被认为是一种可接受的现代方法?
  • Can I use the technologies already adopted in the web application (WCF)? 我可以使用Web应用程序(WCF)中已采用的技术吗?
  • Where do I start? 我从哪里开始?

If you already have a WCF service implemented for posting the tickets, then I can't see it being a huge effort to extend the service and add a method for listing tickets. 如果您已经实现了用于发布票证的WCF服务,那么我认为扩展服务并添加列出票证的方法是一项巨大的工作。

For performance you can have an overload which accepts a date, allowing you to get all tickets raised after that date. 为了表现,您可以拥有一个接受日期的超载,允许您获得在该日期之后筹集的所有门票。 - This means your first request can get all tickets, and future requests with date of last request included will only get new tickets. - 这意味着您的第一个请求可以获得所有票证,并且包含上次请求日期的未来请求将仅获得新票证。

Consume the service with the new method from your windows forms application and poll it at regular intervals. 使用Windows窗体应用程序中的新方法使用该服务,并定期轮询它。 Then just pop up your balloon tip when the service returns new tickets. 然后只需在服务返回新票证时弹出气球提示。

You can create a DuplexService. 您可以创建DuplexService。 ie Specify a CallbackContract by which the technicians will receive notifications. 即指定技术人员将通过其接收通知的CallbackContract。 Duplex is a bit none standard though. 虽然双工是没有标准的。

    [ServiceContract(Namespace=ServiceContractNamespaces.ServiceContractNamespace,
                 CallbackContract = typeof(ISupportTicketCallback))]
public interface ISupportTicketService
{
           [OperationContract]
           int CreateSupportTicket (SupportTicket supportTicket);
}
public interface ISupportTicketCallback
{
        [OperationContract]
        void SupportTicketCreated(int supportTicketId);
}

Alternatively your WCF Service can publish messages via MSMQ to the technician's application. 或者,您的WCF服务可以通过MSMQ将消息发布给技术人员的应用程序。

In either case, notifications will be event driven. 在任何一种情况下,通知都将是事件驱动的。 No polling required. 不需要投票。 Very clean solution:) 干净的解决方案:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM