smithdale87
asked on
Web Service to Window Service communication
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
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
Normally, the windows service would send requests to the web service. Sounds like you want to do it the other way.
ASKER
Yes, that seems to be the case. Any ideas?
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
AW
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.
In order to exchange info with the Web Service, the Windows service would need to initiate the conversation by calling a Web Service method.
ASKER
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?
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?
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.
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.
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.
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
Google "Host WCF by windows service" should give you some hints.
Good Luck
ASKER
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.
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.
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
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
ASKER
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?
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?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.