How to pack a staff-wsf service component directly into the axis_http_server executable, so you don't have it in a separate shared library?
Related
I know how to write a dll and how to write a service and how to run a dll with rundll32, but now I want to write a dll that install as a service in windows
I don't know if that's possible or which function in dll should be exported?
How can I install and run a dll as a service?
There are a few different ways to run a DLL as a service. You can either:
Write your own .exe service and have it load your DLL as needed. This is the recommended approach.
Use Microsoft's SVCHOST.EXE to host your DLL. Have your DLL export a ServiceMain() function, add a ServiceDLL value to your service's Registry key to point at your DLL, add your service name to a new group in SVCHOST's Registry key, and then set svchost -k <GroupName> as the executable for your service. See these articles for more details:
A description of Svchost.exe
Getting Started with SVCHOST.EXE Troubleshooting
Tricks with SVCHOST.EXE
The Service Host
Note, however, that MSDN's Service Programs documentation warns against this approach:
A service program created with the type SERVICE_WIN32_SHARE_PROCESS contains code for more than one service, enabling them to share code. An example of a service program that does this is the generic service host process, Svchost.exe, which hosts internal Windows services. Note that Svchost.exe is reserved for use by the operating system and should not be used by non-Windows services. Instead, developers should implement their own service hosting programs.
Write your service as a kernel-mode driver that exports a DriverEntry() function, and add a ServiceDLL value in your service's Registry key pointing at the DLL file. See this article for more details:
Driver Development Part 1: Introduction to Drivers.
I would not recommend this approach, unless you are designing your own hardware.
There's actually no inherent reason why you can't use rundll32.exe as the host executable, though use of rundll32 isn't recommended. (To expand on that: I gather you're trying to build a DLL service as an academic exercise, which is fine. In production, you should of course use an EXE, as you've already done.)
Your main function should have this signature:
void CALLBACK MyServiceEntry(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
and should call StartServiceCtrlDispatcher, in the same way as the main() or WinMain() function in a conventional service.
You would then install the service to use the following command line:
rundll32 MyService.dll,MyServiceEntry
For an academic exercise, it would also be acceptable to use svchost.exe as described in Remy's answer, but it is even more important not to use that in a production context: the use of rundll32 by third parties is supported but not recommended; the use of svchost by third parties is explicitly unsupported.
I've a C++ application with multiple classes and I should make available their methods over a Thrift service using the same port.
Actually, according with documentation, the only way seems to create a single class using thrift generator that call other class methods.
Instead, I would like to directly use native class methods. Is it possible to create a service that supports multiple handlers/processors? Or multiple services on the same port?
P.S. I'm pretty new to Thrift.
Service multiplexing is implemented since 0.9.1. Look here for details and samples: https://issues.apache.org/jira/browse/THRIFT-563
Here's a link on related question: I'd like to use multiple services on one transport ( Thrift )
I have a web application mostly written by others based on JSF 2, Mybatis, Spring 3 and tens of other libraries, running on Weblogic, it works and now I have to create a distinct command line application to schedule the running of some tasks already present in the web app.
I added a class with a main method in order to maintain only one codebase with a different build process to generate an executable JAR instead of a WAR. Using Spring's ClassPathXmlApplicationContext I managed to recreate the web application context, access the database beans and use them, but I'm stuck with a WSRR call which fails.
The commands:
GraphQuery graphQuery =
(GraphQuery)DataFactory.INSTANCE.create(TypeConstants.SR_URI, TypeConstants.TYPE_GRAPHQUERY);
graphQuery.setQueryExpression("/WSRR/GenericObject[#CFT_APPLIC='DS" + param + "']");
fail with a long stack, having the root exception
Caused by: java.lang.NullPointerException
at java.util.ResourceBundle.getBundle(ResourceBundle.java:960)
at com.ibm.ws.webservices.engine.resources.ProjectResourceBundle$Context.loadBundle(ProjectResourceBundle.java:474)
at com.ibm.ws.webservices.engine.resources.ProjectResourceBundle.getBundle(ProjectResourceBundle.java:372)
at com.ibm.ws.webservices.engine.resources.ProjectResourceBundle.getBundle(ProjectResourceBundle.java:341)
at com.ibm.ws.webservices.engine.resources.MessagesConstants.<clinit>(MessagesConstants.java:93)
I found that some classes and configurations are provided at runtime by the application server, and have no idea about how to replace them outside the application server.
The IBM redbook says (pages 120-121) that is possible to access a web service using a Java client, but requires a suitable EJB runtime.
How can I replicate needed EJB parameters outside the application server? I tried to use the Eclipse debugger to follow the execution of the application and extract them, but it fails, probably because the classes are loaded by Weblogic classloader.
There is an excellent article by Young Yang that explains how to use wsimport to create web service client artifacts that have asynchronous web service calls. Asynchrony requires that the WSDL has the tag
<enableAsyncMapping>true</enableAsyncMapping>
in its bindings section. If you are using the bottom-up approach with JAX-WS annotated Java classes you can't do this directly in the WSDL because the WSDL is a generated artifact on the web server. Instead you use build tools like Ant or Maven to include this binding when wsimport is executed on the WSDL.
The generated client artifacts have asynchronous method calls that return a
Future<?>
or a
Response
which is a Future.
My question after reading Yang's article is why not just roll my own asynchronous web service calls using Executors and Futures. Do the artifacts created by wsimport offer some advantage that I can't see over a roll-your-own approach?
If anyone has experience or insight with both approaches I would appreciate your feedback.
In theory, the generated asynchronous clients wouldn't need to block threads. By passing an AsyncHandler, the system can use NIO to register for an event when the web service call is complete, and it can call that handler. No threads need to block at all.
If you put your synchronous web service call into an executor, it will still end up blocking a thread until the result arrives, although at least this blocking is limited to the thread pool in the executor.
As soon as you have many hundreds of threads floating around, your system performance will degrade due to context switching.
Whether the web service library under the hood actually uses NIO is another matter. It doesn't appear to be required by the JAX-WS specification. Using JDK 1.6 and setting a break point server side, I set 100 clients off to call the server. Using JVisualVM I attached to the client and could see that it had created one new thread per call to the server. Rubbish!
Looking around on the web I found that Apache CXF supports limiting the pool of threads used in async calls. Sure enough, using a client generated with CXF and putting the right libraries on the classpath as discussed here, a retest showed that only 25 threads were being used.
So why use the jax-ws API rather than build your own? Because building your own takes more work ;-)
I know that it does not reach the prompted question, but just complementing one information included on question:
"Instead you use build tools like Ant or Maven to include this binding when wsimport is executed on the WSDL."
It is possible generate the asynchronous client by a adding a custom xml file using the option -b to the wsimport:
Example:
wsimport -p helloAsyncClient -keep http://localhost:8080/helloservice?wsdl -b customAsync.xml
The customAsync.xml content:
<jaxws:bindings
wsdlLocation="http://localhost:8080/helloservice?wsdl"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
<jaxws:enableAsyncMapping>true</jaxws:enableAsyncMapping>
</jaxws:bindings>
It is just one more way to generate asynchronous client beyond by using ant or maven :)
Assume I have simple program (executable compiled from a C program)that provides text information running as Windows XP service. AFAIK Windows service can communicate with any external process running on the same PC but not with remote processes. How can I convert this windows service to SOAP Web service so that it responds to any any SOAP requests from any remote host?
What are the steps for this like what library to use (not .NET) ?
There's no magic library that will do it for you, you have to create a Program yourself and expose a SOAP endpoint with the service functionality.
Windows processes can communicate with other processes if those process offer a way for that communication to happen (inter-process messaging, reading system event queues, etc), so assuming your C program do offers a way for that communication to happen, your new program can feed that program the input, get the text information and return it to the client consuming your web service.
If you don't want to use .NET maybe you can use some other high level language like Java, Ruby or Python than can help you get your service up un running faster, but you have to create a program yourself, there's no magic library to wrap a program in and make it a SOAP web service.