ITPub博客

首页 > IT基础架构 > 网络安全 > Tomcat+ApacheSOAP部署访问COM对象的WebService (转)

Tomcat+ApacheSOAP部署访问COM对象的WebService (转)

原创 网络安全 作者:worldblog 时间:2007-12-12 10:02:19 0 删除 编辑
Tomcat+ApacheSOAP部署访问COM对象的WebService (转)[@more@]

如果大家用过微软SOApToolBox的话,一定会知道部署一个访问COM对象webservice是非常简单事情。而在Java环境下,要完成这件事情也不是很复杂。以下是我通过WebService访问一个简单COM对象,只包含一个简单的SayHello方法返回字符串。

我的环境是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.-->
id="urn:WebDll-COM">
SCOpe="Application"
methods="SayHello">



org.apache.soap.server.domFaultListener


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

文中不妥处请指教,zlyperson@163.net


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752043/viewspace-991638/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    6241
  • 访问量
    2405521