http://www.fx120.net/dnjc/java/javazh/200512271045346199.htm
--------------------------------------------------
Tomcat+ApacheSOAP部署访问COM对象的WebService
文章来源: 2005-12-27 11:24:48
<p style=line-height: 150%>如果大家用过微软的SoapToolBox的话,一定会知道部署一个访问COM对象的WebService是非常简单事情。而在java环境下,要完成这件事情也不是很复杂。以下是我通过WebService访问一个简单COM对象,只包含一个简单的SayHello方法返回字符串。
<p style=line-height: 150%>我的环境是tomcat4.0+apachesoap,其中tomcat在http://jakarta.apache.org/site/binindex.html
下载,apachesoap在http://xml.apache.org/dist/soap/下载。
步骤:
1。把soap.jar包含到classpath
2。把COMProvider.dll所在路径设置到Path
3。VB写一个COM对象代码如下
‘WebDll.SimpleMath
Public Function SayHello() As String
SayHello = "Hello From Com Object"
End Function
编译生成WebDll.dll
4。写一个部署描述文件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。部署
java org.apache.soap.server.ServiceManagerClient http://localhost:8080/soap/servlet/rpcrouter deploy WebDll.xml
6。客户端程序
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 String serverport= "8080";
static String soapservlet= "/soap/servlet/rpcrouter";
} // end addit
7。测试运行
编译JClient启动Tomcat
运行java JClient
返回结果
Hello From Com Object