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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值