Tomcat+ApacheSOAP部署訪問COM物件的WebService (轉)

worldblog發表於2007-12-12
Tomcat+ApacheSOAP部署訪問COM物件的WebService (轉)[@more@]

如果大家用過的pToolBox的話,一定會知道部署一個訪問COM的service是非常簡單事情。而在環境下,要完成這件事情也不是很複雜。以下是我透過WebService訪問一個簡單COM物件,只包含一個簡單的SayHello方法返回字串。

我的環境是4.0+soap,其中tomcat在
,apachesoap在http://.apache.org/dist/soap/下載。
步驟:
1。把soap.jar包含到classpath
2。把COMProvr.dll所在路徑設定到Path
3。VB寫一個COM物件程式碼如下
‘WebDll.SimpleMath
Public Function SayHello() As String
SayHello = "Hello From "
End Function
編譯生成WebDll.dll
4。寫一個部署描述WebDll.xml
<!--Apache SOAP specific deployment descriptor (loads this service into Apache SOAP.--&gt
id="urn:WebDll-COM">
pe="Application"
methods="SayHello">



org.apache.soap.server.FaultListener


5。部署
java org.apache.soap.server.ServiceManagerClient deploy WebDll.xml

6。客戶端
import java.io.*;
import java.*;
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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章