问题
I am using .Net 2.0 framework and would like to call a function in Windows service from a web service. Is this possible? And If yes, how much control I will have over the function i.e passing parameters, getting the result back etc. Any ideas would be greatly appreciated :)
回答1:
Remoting is your best option if you need to pass parameter values.
If you don't need to share objects or anything too complex, ServiceController is probably easier.
回答2:
You can do it through .NET remoting. If you go that route, it will appear you are calling a method and getting a result, but all your parameters will be serialized over the wire, and the result will be serialized back. Therefore, everything must be made serializable.
回答3:
How about hosting a WCF service inside of the Windows Service. You can use net.tcp or named pipes to communicate between "your" web service and the one in the Windows Service. You can use the NetDataContractSerializer for serialization with type fidelity.
回答4:
You could implement a basic http server that maps certain requests to functions. Query-string will be mapped to parameters. Actually not hard and I have done this in the past (as I provided some rudimentary template-based reporting). It wasn't dynamically, but it could be done dynamically. Look at HttpListener for a starting point. You could as well host the asp.net engine in it.
It has it advantages and disadvantages.
回答5:
Why not package the function in its own DLL then distribute it with the Windows Service and the Web Service separately?
回答6:
Create service project what export an interface COM or use PIPE to transfer data. View this Interprocess Communication using Named Pipes in C#
来源:https://stackoverflow.com/questions/687608/calling-windows-service-from-a-web-service