Solved

Web Service to Window Service communication

Posted on 2008-06-14
13
1,704 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
  • 4
  • 3
  • 2
  • +2
13 Comments
 
LVL 18

Expert Comment

by:Gary Davis
Comment Utility
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
Comment Utility
Yes, that seems to be the case. Any ideas?
0
 
LVL 44

Expert Comment

by:Arthur_Wood
Comment Utility
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
 
LVL 14

Expert Comment

by:ptakja
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 13

Expert Comment

by:joechina
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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 250 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now