Http://www.fx120.net/dnjc/java/javazh/200512271045346199.htm
--------------------------------------------------
Tomcat + ApacheSOAP deploy the WebService to access the COM Object
Source: 2005-12-27 11:24:48
<P style = line-height: 150%> if you have used Microsoft's SoapToolBox, you will surely know that deploying a WebService to access COM objects is very simple. In the java environment, it is not very complicated to do this. The following is a simple COM object that I access through WebService. It only contains a simple string returned by the SayHello method.
<P style = line-height: 150%> my environment is atat4.0 + apachesoap, where tomcat is in the http://jakarta.apache.org/site/binindex.html
Download apachesoap at http://xml.apache.org/dist/soap.
Steps:
1. Include soap. jar into classpath
2. Set the Path of COMProvider. dll to Path
3. The following code is used to write a COM Object in VB:
'Webdll. SimpleMath
Public Function SayHello () As String
SayHello = "Hello From Com Object"
End Function
Compile and generate WebDll. dll
4. Write a deployment description file WebDll. xml
<! -- Apache SOAP specific deployment descriptor (ie loads this service into Apache SOAP. -->
<Isd: service xmlns: isd = "http://xml.apache.org/xml-soap/deployment"
Id = "urn: WebDll-COM">
<Isd: provider type = "org.apache.soap.providers.com. RPCProvider"
Scope = "Application"
Methods = "SayHello">
<Isd: java class = "required not needed for COMProvider"/>
<Isd: option key = "progid" value = "WebDll. SimpleMath"/>
</Isd: provider>
<Isd: faultListener> org. apache. soap. server. DOMFaultListener </isd: faultListener>
</Isd: service>
5. Deployment
Java org. apache. soap. server. ServiceManagerClient http: // localhost: 8080/soap/servlet/rpcrouter deploy WebDll. xml
6. Client Program
Import java. io .*;
Import java.net .*;
Import java. util .*;
Import org. apache. soap .*;
Import org. apache. soap. rpc .*;
Public class JClient
{
Public static void main (String [] args) throws Exception
{
Integer n1 = null;
Integer n2 = null;
Final String urn = "urn: WebDll-COM ";
Vector params = new Vector ();
URL url = new URL ("http: //" + serverhost + ":" + serverport + soapservlet );
// Build the call.
Call call = new Call ();
Call. setTargetObjectURI (urn );
Call. setMethodName ("SayHello ");
Call. setEncodingStyleURI (Constants. NS_URI_SOAP_ENC );
Call. setParams (params );
Response resp = call. invoke (/* router URL */url,/* actionURI */"");
If (resp. generatedFault ()){
Fault fault = resp. getFault ();
System. out. println ("Ouch, the call failed :");
System. out. println ("Fault Code =" + fault. getFaultCode ());
System. out. println ("Fault String =" + fault. getFaultString ());
} Else {
Parameter result = resp. getReturnValue ();
System. out. println (result. getValue ());
}
}
Static String serverhost = "localhost ";
Static strings serverport = "8080 ";
Static String soapservlet = "/soap/servlet/rpcrouter ";
} // End addit
7. Test Run
Compile JClient to start Tomcat
Run java JClient
Returned results
Hello From Com Object