Beginners WCF Question - Consumable asynchronous services

元气小坏坏 提交于 2019-12-04 13:38:47

问题


this is a more "can it be done" rather than a "how is it done" question. I'm looking at building a service (middle tier, .net, providing data abstraction and some business logic) that will be used by multiple internal client systems on different platforms. E.g. one client might be a web site, another client some java code, another client C#, etc.

I want to provide a synchronous and asynchronous API into my service, e.g. GetData, BeginGetData, EndGetData methods. I also want clients to be able to register for notifications of new "data" being added to the system. In the past I've implemented this using web services with a Tibco EMS channel for the notifications.

My question is: Could I achieve the three requirements (synch, asynch, and pub/sub) by exposing a WCF service? Could this service by consumed by non WCF clients?

Excuse the vagueness of this question - I can elaborate as needed.

Thanks in advance.


回答1:


Methods are synchronous by default. To make them asynch, you need to add this attribute [OperationContract(AsyncPattern=true)] and return an IAsynchResult, just like you would if you were doing BeginIvoke() with winforms. (read more here http://msdn.microsoft.com/en-us/library/ms734701.aspx)

You can do publish/subscribe with something called a Callback Contract (although im not sure about implementing this in other platforms) I don't have much experience with these, but they don't seem hugely complected(you can read more here http://dotnetaddict.dotnetdevelopersjournal.com/wcf_alarmclock.htm)




回答2:


Setting up async operations on your WCF service can be done as Ninja posted by setting AsyncPattern=true or it can be done on the client side by telling svcutil to generate the async end points by setting the correct command line argument or by checking the "Generate asynchronous operations" option in the GUI version of svcutil. Generating async will still generate synchronous operations as well.

The issue with the client async option is you will need to duplicate the code in Java. Svcutil does export VB or C# code as you specify so you could very likely translate the C# code to Java without too much work.

For Pub/Sub, client callbacks are how you want to operate. I am using them and they work very well. At the root level, they are .Net Remoting and use eventing to pass the data to the client (my understanding). I cannot confirm that this could be used cross platform but it should be with some work.



来源:https://stackoverflow.com/questions/353383/beginners-wcf-question-consumable-asynchronous-services

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!