I am currently building a WCF Service to make use of some DLL's that are not UWP compatible at the moment. I've gotten my service running, included, and accessible from my UWP app but because I'm very new to WCF I'm not sure the best way to go about reporting the status of certain activities of the WCF Service. Specifically, I have a function that I call from my service that does some things, reaches a certain point, and then does some more things. I would like the notify the UWP app that this certain point has been reached. How would I go about doing this?
I've looked into callbacks but I haven't found a clear resource on them and am hoping there is a simpler way to accomplish what I'm looking for.
Edit: After doing some reading on the various forms of communication in WCF(mainly duplex and subpub) I think my solution will be more along the lines of subpub although it seems like overkill. From what I've seen I would be unable to make 2 callback calls from within one service function call and that would be ideal.
Edit: So apparently I am able to make 2 callback calls from a service function by modifying my ServiceContract to something like:
[ServiceContract(SessionMode = SessionMode.Required,
CallbackContract = typeof(IRecordServiceCallback_duplex),
CallbackContract = typeof(IRecordServiceCallback_duplex))]
So now I know that's what I'm trying to accomplish.
Update:
My problem now, I've looked through various examples and none of them seem to implement a duplex wcf service without some other complications which make understanding what's going on a bit difficult. Or they are missing the config file. Ideally I think I'd like to have a Duplex WCF Service hosted in IIS that communicates to a Windows Universal App, I'm currently hung up on how to call my duplex wcf service from within a UWP app. I've called a basic WCF Service before so I'm sure it can be done.
Related
I'm trying to build basic prototypes from a project that will take form a little later down the road.
For this prototype I currently have a console application hosting WCF services and another console application consuming the WCF services.
I have read of the three different message patterns for WCF and from what I understand I can either :
1)Call the WCF service and wait for the answer, locking the consumer while its waiting for the answer.
2)Call the WCF service asynchronously, which doesn't lock the consumer while its waiting for the answer. An answer event will eventually happen.
3)Call the WCF service without expecting and answer at all.
What I would like to know is if it is possible to use WCF to send a message to the client when an event is triggered on the service side. For example if a variable changes on the application hosting my services, a message would be sent to a client.
The only way I can imagine this would be to have my client also host WCF services and send a one way message from my initial host as the client.
This seems like a somewhat odd way of doing things for some reason and I would love to know if anybody has another idea on how this could be done.
Thanks a lot!
Note: Just in case anybody gets stuck on that, I am not looking for a way to trigger events when a variable changes. Also, there is no code in the question because it is mostly an architectural question. If you can point me towards the right tools to achieve what I'm looking for I'm sure i'll find plenty of code examples on how to use them!
I'm new at WCF and I've got one problem, and I don't have an idea how to solve it.
I've got Windows Service app listening to COM ports, and GUI WPF app for configuring Windows Service app. Among that my idea is to send notification to WPF app every time when something comes to COM port and maybe send that data to WPF.
For communicaton between those two clients I use WCF, and for sending data from WCF service to WPF app I got to use callbacks.
I got to use two different ServiceContracts because of two different clients. One of ServiceContacts supports callback method, and one of them not so there are two different bindings.
Is there any way to invoke callback method implemented on WPF app when WS gets data from COM port. On WS I invoke proxy method defined in ServiceContract for WS, and get data in WCF service but when I invoke callback its always null. I know that there is problem with OperationContext and I know what problem is but I dont know how to solve it, or is there any way to solve it.
Please help me and thank you.
I think duplex WCF (i.e. contract with Callback) is one way to go if your WFP client is normally calling the "service" via WCF anyway. You will obtain the callback context in the "service" contract class (its constructor usually) and then use it to forward anything to the WPF client at any time. Google "Duplex WCF".
However this is a situation for which in enterprise scale you will use a middleware solution, i.e. a separate "message queue/bus" infrastructure to which the WPF clients subscribe and get their updates. If no one is subscribed, messages are sent to /dev/null. The "service" publishes everything to the bus at any case.
I am creating windows service, which must be able to receive commands from client located on other computer.
So far it seemed like using WCF for comunication is a good idea. However I am unable to pass any argument to my service on server side. All tutorials on WCF show only basic methods, which do not interact witch windows service.
Is there any way how to communicate with windows service? - Be able to call methods, that return some data. Using WCF it feels like I am only a step away. I can call methods on server and getting data back. I am however not able to access parameters of the service to modify them.
Basicaly what I want is to have a thread running in the windows service doing periodiccaly some actions, and to be able to remotely interact with it (it is not enough to pass only number code, I need to be able to pass at least string (preferably custom type) and get answer (string or custom type))
Thanks
If you can pass the number you can modify the service contract to use a (custom) data contract including strings and also more complex types. You need to check [DataContract] for more those complex types.
This link covers the basics: http://www.codeproject.com/Articles/653493/WCF-Hosting-with-Windows-Service
It starts with creating the service and creating an installer for the windows service.
Starting with the Fourth module there it is explained how to complete coding on the client side.
You need to expose the service metadata for service reference to complete programming the client.
If you have the metadata exchange, you can also check if you can find the hosted WCF service with tools like the WCFtestclient.
I created WCF service and faced with a problem. I need to update database periodically, but i couldn't find static method like Main, that whould do it without client interaction. What can i do??? What wold you suggest in such case?
There is no Main method (or similar entry point) in WCF. You need to host your WCF service in another process (such as a Windows service, or IIS or self host) to "activate" it and make it available to other processes.
One of the concepts in WCF is that you write your service code to do the function you need without having to worry about infrastructure and hosting. Once you have written your service logic, you can then decorate and configure your service to expose it to other processes. Using this approach means you can change how your service is exposed to other processes without re-writing the actual service logic - you essentially just change your configuration. Hence, a main entry point is specific to how you choose to host and expose your WCF service to the outside world.
Just Google around for "WCF hosting" and you will find lots of information.
If you don't need to expose your service logic to an external process (which sounds like maybe the case from your question) then maybe you don't need to use WCF and you can just write a plain old Windows Service.
If your wcf service is self hosted then you can do it in your application before publishing the service.
If it is in IIS then there really isn't application_start kind of thing since the host may be created on first request. See WCF application start event
I have following scenario:
alt text http://static.zooomr.com/images/7579022_e64808b855_o.png
We have a WebService which poses as a search-engine, used by WebApps
But as we all know on 32bit systems and IIS6: 800Mb is the max. alloc-mem for a webapp...
Now I had the following idea, as we are exceeding this limitation:
alt text http://static.zooomr.com/images/7579028_c423e52b46_o.png
Let the WCF communicate with a Windows Service, which isn't affected by this constraint!
But this brings me to some questions:
How can I communicate with a Windows Service as I would communicate as a client with the WCF (having methods with parameters, getting objects as return value, etc...).
After thinking about this a bit, following post came up to me.
But I'm not familiar with this scenario.
Do some of you know some good resource, where I can get the knowledge to realize this scenario (maybe with demo-apps)?
Or does someone maybe have a better idea of how realize this scenario even more comely?
This scenario wil be completely done with C# 3.0 and .NET 3.5(SP1)...
I would definitely use WCF as the communication layer between the web-app and the service. You can host a ServiceHost in your windows service, and serve up any type of WCF endpoint.
A common pattern I've seen is to connect a web layer and service layer using MSMQ (Net MSMQ binding), so that you have disconnected calls, and some buffering to allow for load tolerance. If you don't need the buffering, you can use any other type of binding (Net TCP or even HTTP, although sometimes it tricky to get HTTP setup correctly outside of IIS).
Here's a good tutorial:
http://msdn.microsoft.com/en-us/library/ms733069.aspx