WCF client hosted in a windows service with a WPF UI - wpf

I have now a WCF service that is hosted inside a WPF application. It's running in a WCF server-client scenario where the client can call the server as well (duplex communications).
I would like to host the WCF client in a windows service, but I'd like to keep the WPF UI because of the functionality it provides when making calls back to the server (e.g. request information). I know that windows services don't have UI, but in this case I need it.
What best way is there to communicate between the WPF application and the windows service? (something better than sockets maybe?)
A scenario where this is useful would be something like:
from the WPF application I can choose what kind of information would be required from the WCF service acting as server,
this "command" would be sent to the windows service hosting the WCF client instance, and
using the the instance making the call to the server and
displaying the information in the WPF application via the WCF client service hosted by the windows service.
Thanks,
Adrian

Since the service is already running as WCF, how about exposing some extra "admin" methods on the WCF interface and have the WPF application interact with the service through those?
You'd have to put in a security layer to make sure only the legitimate user could call those new methods, but this solution might be the least work since the WCF infrastructure is already in place.

Related

make C# window application as window service

I have a desktop application in C# and i want to make that a window service. Is it possible to make that application as a windows service? Basically i want an app that shows gui when needed and upone minimizing it goes to system try, and it should also appear in services... For application just take an example that my application have a timer and multiline text field and its also interacting with database and its showing timely status from database so when i need to see it i can start GUI from system try?
Any kind of help would be highly appriciated. Thanks!
You will need to separate your applications. Windows Service and desktop. You will need to build API hooks into your Windows Service to allow communication from your desktop application and the service. I would recommend WCF for this.
In a nutshell, a Windows Service should not interact with the desktop. It will run in a separate session than the session you are logged into, even if you are logged in as the same account the service is running under.
It is not possible to show GUI in a windows service.
What you can do is:
a. Seperate client logic from server logic, the windows service will perform the server side operations and will expose a WCF API to the client , which will handle the GUI related issues.
b. Use an external tool like Service-O-Matic to control your winforms application as if it was a windows service. see:
http://www.kwakkelflap.com/service.html

Send simple data from wp7 to winforms application

I want to send simple data (geolocation data to be precise) from Windows Phone 7 application to a windows forms application and use it, as I'm a total beginner in this field I don't know which tools to use.
I searched about wcf services and tested this method but there's some issues: the data is sent from the phone application but isn't sent to the winforms application (guess something is missing)
If your know how to do this in a quick way, or have good tutorials I'll be thankful.
EDIT
I found this tutorial, it show how to connect directly wp7 application and desktop application without using sockets neither wcf service, I'm wondering if it is really works if the application isn't in localhost.
the like for the tutorial: wp7 tutorial
I had a similar problem and so I created a REST/JSON WCF service hosted in IIS with AppHarbor to provide the data. There's hundreds of ways to do it (Ruby/Heroku, etc..), but that particular one fits well within the Microsoft stack. I also needed to share route data and I used the WCF service to wrap the BingMaps services so that route computations are cached and shared. Considering that I had already created a local model, moving it out of my phone project into a service took less than a few hours (including the usual config hiccups, and forgetting to add the appharbor user to my bitbucket repo).
Consuming the service from WinForms (or any client) shouldn't be an issue as the service knows nothing about the client implementation.
Here's a tutorial from code project. REST WCF Service with JSON
I think you would need to implement some sort of server side solution which you could upload to on your Windows Phone and download from on your Windows Form application. This could be achieved using a WCF service which was connected to a server side database.
Another option would be to use sockets and communicate directly with your WinForms application. Check this tutorial on how to use basic sockets on WP7.

WCF and multiple clients

I have a WCF hosted in IIS, at the same time I have two clients, a WPF application and a Window Phone Application. My program work in the way that, the Window Phone Application will send a Message to the WCF and then the WCF will send it to the WPF application. How can I achieve it?
I have take a look at callback, but I believe what it does is to return a message back to the Window Phone Application after the Phone Application consume the WCF service. But what I want my program to do is to send the Msg from the Phone App to the WPF application instead.
please guide me. Thank you!
I would probably do it this way:
inside the WPF application, host a second WCF service to receive that message - your WPF application becomes a WCF server
when a message comes in from the Windows Phone into your WCF service in IIS, that service class then becomes a WCF client to the WPF app and send that message onwards to the other WCF service
Callback won't work - since callback can only call back to the original caller (your Windows Phone, here) and that's not what you want.

Silverlight 4 and WCF

I have a WCF service (using HTTP binding) that our WinForm and WFP apps can use with no problem. We have a Silverlight 4 developer who is saying he's not able to use the WCF service because it needs to be "reconfigured" for Silverlight use. I don't know if this is true or not, because I don't know anything about Silverlight.
So, my question is this. Should a WCF service, that uses HTTP binding, that is successfully being used by our WinForms and WPF applications, also be able to be consumed by Silverlight apps, without modifying or reconfiguring the WCF service?
Silverlight 4 supports the following bindings:
BasicHttpBinding
PollingDuplexHttpBinding
CustomBinding (with a subset of binding elements)
Silverlight and WCF Feature Comparison:
There are several ways to use the WCF
client stack to access a service.
It is used when invoking services
through automatically generated
proxies, as described in How to:
Access a Service from Silverlight. The
proxy must be generated in this
procedure by using the Add Service
Reference tool in Visual Studio 2010
for the Silverlight project.
Caution:
Proxies generated by using the WCF
Svcutil.exe tool will not work in
Silverlight 4. Use the SLsvcutil.exe
tool instead. For more information
about using this Silverlight tool, see
Using SLsvcUtil.exe to Access a
Service.
If you already have a Windows
Communication Foundation (WCF) service
contract definition, you can use the
generic ChannelFactory class without
having to generate a proxy. This might
be the case, for example, if your
client is sharing service definition
code with the project on the server.
In this case you could, for example,
define a service contract interface
IStockQuoteService and then use the
same IStockQuoteService code in both
the server and Silverlight projects.
This would involve using a
ChannelFactory.
This advanced technique is
demonstrated in How to: Call
Operations Asynchronously Using a
Channel Factory and in the Silverlight
4 context with Building and Accessing
Duplex Services. For more information
about defining and using service
contracts, see Designing Service
Contracts.

Custom hosting and "Silverlight-enabled WCF service"

I'd like my WP7 to be able to talk to a service on my local computer. For various reasons it would be more convenient if this service was hosted in a custom host, i.e. an app running locally. However, if I understand correctly "Silverlight-enabled WCF service" need asp.net compatibility, therefore must be hosted in IIS, is this correct?
If so, is there anyway to work round this and get a "Silverlight-enabled WCF service" running in a custom host?
The Silverlight-enabled WCF Service is just a simplified item template from a regular WCF service. It was originally added because the default binding for WCF services wasn't supported in Silverlight, and caused a lot of angst for new Silverlight developers. You should be able to use the regular WCF item in a regular project (e.g. console app) and you'll just have to adjust the bindings.
(Also of note is that the Silverlight-enabled WCF template uses a single code file instead of separating out the service interface from the class implementation.)

Resources