Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Web Service to Window Service communication

Posted on 2008-06-14
13
Medium Priority
?
1,712 Views
Last Modified: 2008-07-18
I have a C# windows service running on a local machine, and a webservice running elsewhere (may or maynot be local). Is it possible to pass data back and forth between the webservice and the windows service? I've looked into using the TcpChannel remoting stuff, but there aren't any really good examples.

Say for instance, I want to pass a string from a webservice to a windows service, and modify it within the windows service, then pass the modified string  back to the webservice, how would I go about that?

Thanks
0
Comment
Question by:smithdale87
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
13 Comments
 
LVL 18

Expert Comment

by:Gary Davis
ID: 21788525
Normally, the windows service would send requests to the web service. Sounds like you want to do it the other way.
0
 

Author Comment

by:smithdale87
ID: 21788814
Yes, that seems to be the case. Any ideas?
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 21795997
The name is "Service", meanin gthat the software provides a 'service', at the request of some other software.  SO, normally there is a client, of some kind, which issues a request to the service, which then responds.  Since you have two service, how is the initial request supposed to be issued?  The Windows Service normally does not initiate a request, nor does the Web Service.  How is the request to be initiated?

AW
0
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 14

Expert Comment

by:ptakja
ID: 21796061
I am with Arthur Wood on this one. In order to use a Web Service, an application has to essentially "subscribe" to the web service by making a reference to that service. Thus the act of subscribing dictates that the subscriber is the client. So in your case, assuming that the Windows service subscribes to the Web Service, your Windows service becomes the client.

In order to exchange info with the Web Service, the Windows service would need to initiate the conversation by calling a Web Service method.

0
 

Author Comment

by:smithdale87
ID: 21796297
Makes sense. Thanks.

The reason I am asking is because one of my co-workers asked me if it was possible for me to develop a series of applications such that a Java client passed a string object to a web service, which then passed the string on to a windows service, which then calls a local c++ dll to modify the string. Of course everything has to be passed by reference rather than by value.

However, I'm guessing the only solution is that once the string reaches the web service, the windows service should be continuously polling the web service to see if the web service has received the string from the Java client yet. If so, get that string, and pass it along to the DLL.

Sound more feasible?
0
 
LVL 14

Expert Comment

by:ptakja
ID: 21796324
Be careful there. Each new web service instance runs in it's own session on the web server. You can create global variables to share between sessions, but that can get messy real quick.
0
 
LVL 13

Expert Comment

by:joechina
ID: 21796468
Hi, smithdale87,

Why a windows service to do the job?
Could you just wrap the c++ dll with a web sercive? It will make things much easier. (or even a COM object.)
Your polling solution will work, but it's not a good solution.

0
 
LVL 13

Expert Comment

by:joechina
ID: 21796506
If you just don't want to install IIS on that server, you can build a windows service which which host a WCF service.
Google "Host WCF by windows service" should give you some hints.
Good Luck
0
 

Author Comment

by:smithdale87
ID: 21796824
joechina,

I'm not sure what the reason for the windows service is. Initially, my co-worker wanted java->web service->dll, but then at the last minute he threw in the windows service as an intermediate step. I assume it has some direct application to something he may be working on.
0
 
LVL 18

Expert Comment

by:Gary Davis
ID: 21797311
Actually, a web service interface to a windows service is a pretty good idea. However, the windows service should not periodically probe the web service. When the web service gets a request from the client, it should notify the windows service. Windows services are always looking for things to do so this would just be another input.

For example, let's say you wrote a print spooler service that took jobs to print from various local apps. A web service could control that windows service like get the list of print jobs on the queue or shut down the spooler. Then you have control from the internet to your windows service. There are many other examples.

I just don't know the best way for this IPC (interprocess communication from web service to windows service). Traditional IPC techniques are shared memory, named pipes, semaphores, message queues and of course TCP/IP sockets. I't sure there are other options.

Gary Davis
0
 

Author Comment

by:smithdale87
ID: 21797581
Finally, someone who actually sees things my way :-)

As far as the WebService to Windows Service ipc, i've looked into using C#'s TcpChannel class but it only seems to allow me to create a remote object that is hosted on the local machine ( ie where the windows service is running ). So theoretically, the remote object should have access to a local DLL. I could just create a new remote object from the webservice, which will then be hosted on the local machine. The problem is when I call the DLL from within the remote object, and pass a string by reference to the DLL to be modified, it doesn't seem to affect it. It appears that eveyrthing is done on the stack and just disappears when the call returns from the DLL.

However, with a primitive int, if I pass it by ref, and modify it inside the DLL, then the changes appear back on the java client side. Not the same with the string object. I'm not sure why. Any insight?
0
 
LVL 13

Accepted Solution

by:
joechina earned 1000 total points
ID: 21798435
Look at the following two links, it should help:
A simple WCF sample:
http://weblogs.asp.net/ralfw/archive/2007/04/14/a-truely-simple-example-to-get-started-with-wcf.aspx
And how to host WCF with windows service:
http://msdn.microsoft.com/en-us/library/ms733069.aspx

You can pass a reference to a remote serice.
The object has to be serialized and deserialized.
WCF hides a lot of low level serialization and communication and makes your life much easier.

TcpChannel would work but more effort.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question