简体   繁体   English

如何使用自托管WCF服务

[英]how to work with Self hosted WCF service

I have successfully hosted the WCF service in windows forms application. 我已经在Windows窗体应用程序中成功托管了WCF服务。 Now what I need is a way when my service is used by any client i want to show in the form where the service is hosted that last accessed date and time from the client machine and client id. 现在,我需要一种方法,当我想以任何形式使用我的服务时,我想以客户端计算机和客户端ID上次访问日期和时间的形式托管该服务。

So when ever my client is using any operation on my service is also sending me its date and time as well everything is working fine but unable to display it on the form in a label. 因此,当我的客户在我的服务上使用任何操作时,也会向我发送其日期和时间,并且一切正常,但是无法在标签上的表单上显示它。

Can somebody suggest me please. 有人可以建议我吗。

Thanks 谢谢

My suggestion would to use the logging and tracing that comes with WCF, you will have to write custom code to read the client logged information 我的建议是使用WCF附带的日志记录和跟踪,您将必须编写自定义代码来读取客户端记录的信息

Please see links that might help you 请查看可能对您有帮助的链接

http://msdn.microsoft.com/en-us/library/ms730918.aspx http://msdn.microsoft.com/en-us/library/ms730918.aspx

http://msdn.microsoft.com/en-us/library/aa751795.aspx http://msdn.microsoft.com/en-us/library/aa751795.aspx

I suggest using the Microsoft Message Queue (MSMQ), which plays nicely together with WCF . 我建议使用Microsoft消息队列(MSMQ),它与WCF可以很好地配合使用 MSMQ is lightwheight to use and fast, and the best of it, it is built-in into Windows and supported out-of-the-box into .NET Framework. MSMQ轻巧易用且速度很快,它的优点是它内置于Windows中,并已开箱即用地支持.NET Framework。 You can decide to send messages transactional and persisted or have them priorised, if you wish. 如果愿意,您可以决定以事务性和持久性方式发送消息,也可以优先发送消息。

The WCF service would send a message with your needed information each time an operation is called that you want to log in your WinForms application. 每次调用您要登录WinForms应用程序的操作时,WCF服务都会发送一条消息,其中包含您所需的信息。

The Forms application would then receive the message asynchronously and write onto your screen or logfile or wherever you need. 然后,Forms应用程序将异步接收消息,并将其写到屏幕或日志文件上,或在任何需要的地方。

Reading and writing from/ to the MSMQ in C# is straightforward. 在C#中读写MSMQ很简单。

Here is a good starting point: Tom Hollander's blog 这是一个很好的起点: Tom Hollander的博客

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

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