.Net/C# 与 J2EE/Java Web Service 互操作完整实例
.Net/C# 与 J2EE/Java Web Service 互操作完整实例
关键字: Web Service.Net 与 J2EE/Java Web Service 互操作完整实例
实现支持文件分块多点异步上传的 J2EE/Java Web Services 及其 .Net 非 Web 客户端应用程序异步上传
本文参考:
实现支持文件分块多点异步上传的 Web Services 及其客户端(非Web)应用程序调用相关异步执行的 Web Method
http://blog.csdn.net/playyuer/archive/2004/12/11/213069.aspx
升级到 JDK 5.0 Update 1 or 2 定制部署 WebServices - Axis 终于正常了!
http://blog.csdn.net/playyuer/archive/2005/03/01/306360.aspx
为了使程序及环境简洁,本文均使用最简陋的 NotePad 编写程序或配置环境,命令行编译程序!
不使用任何集成开发环境(IDE)!
相关源程序下载:
https://files.cnblogs.com/Microshaoft/jws.net.rar
Sever Side:
采用 Resin/Tomcat + Axis 来部署 java Web Service。
1.首先确认 Windows 系统中安装(不一定要安装,解压到目录即可)了如下软件:
J2SE(TM) Development Kit 5.0 Update 4 (JDK 5.0 Update 4):
http://java.sun.com/j2se/1.5.0/download.jsp
Web Application Server: Resin/Tomcat 二者有其一即可:
Resin v2.1.16:
http://www.caucho.com/download/resin-2.1.16.zip
Tomcat v5.5.9:
http://apache.justdn.org/jakarta/tomcat-5/v5.5.9/bin/jakarta-tomcat-5.5.9.zip
下载后解压到某目录,如:
D:\dotNet.J2EE\resin-2.1.16\
或
D:\dotNet.J2EE\jakarta-tomcat-5.5.9\
Web Services - Axis
http://apache.freelamp.com/ws/axis/1_2_1/axis-bin-1_2_1.zip
下载后解压到某目录,如:
D:\dotNet.J2EE\axis-1_2_1\
然后将该目录下的 webapps 下的 axis 子目录,复制到:
D:\dotNet.J2EE\resin-2.1.16\webapps\
或
D:\dotNet.J2EE\jakarta-tomcat-5.5.9\webapps\
即生成如下路径:
D:\dotNet.J2EE\resin-2.1.16\webapps\axis\
或
D:\dotNet.J2EE\jakarta-tomcat-5.5.9\webapps\axis\
至此就具备运行 Axis 的基本条件了:
先做一下 Java Web Application Server 端口配置到 1080:
(如果你的端口不冲突,可以跳过此步)
Resin:
D:\Resin\resin-2.1.16\conf\resin.conf 用 IE 访问:
http://localhost:1080/axis/
应该看到:
Apache-AXIS 主页
点击超链接:
Validation - Validate the local installation's configuration
see below if this does not work.
访问页面:
http://localhost:1080/axis/happyaxis.jsp
就可以检测当前环境是否满足运行 Apache-AXIS。
根据页面提示下载到所有 zip 文件:
http://192.18.97.238/ECom/EComTicketServlet/BEGIN8656005BAB2BAA9A4B1688FB7D4AF765/-2147483648/972910143/1/359918/359906/972910143/2ts+/westCoastFSEND/7017-jaf-1.0.2-oth-JPR/7017-jaf-1.0.2-oth-JPR:1/jaf-1_0_2-upd2.zip
http://192.18.97.186/ECom/EComTicketServlet/BEGIN87ACAEFABC9A644DBEC89773E476BF24/-2147483648/972928407/1/540782/540770/972928407/2ts+/westCoastFSEND/javamail-1_3_2-oth-JPR/javamail-1_3_2-oth-JPR:1/javamail-1_3_2-upd.zip
http://xml.apache.org/security/dist/java-library/xml-security-bin-1_2_1.zip
各自解压后得到所需所有 jar 包文件:
activation.jar
axis-ant.jar
axis.jar
commons-discovery-0.2.jar
commons-logging-1.0.4.jar
commons-logging-api.jar
commons-logging.jar
imap.jar
jaxrpc.jar
log4j-1.2.8.jar
mail.jar
mailapi.jar
pop3.jar
saaj.jar
smtp.jar
tt.txt
wsdl4j-1.5.1.jar
xalan.jar
xercesImpl.jar
xml-apis.jar
xmlsec-1.2.1.jar
xmlsecSamples-1.2.1.jar
xmlsecTests-1.2.1.jar
将这些文件全部复制到如下目录:
D:\dotNet.J2EE\resin-2.1.16\webapps\axis\WEB-INF\lib
或
D:\dotNet.J2EE\jakarta-tomcat-5.5.9\webapps\axis\WEB-INF\lib
再次访问:
http://localhost:1080/axis/happyaxis.jsp
以验证是否完全满足运行 Apache-AXIS 的环境,
如无错误就说明已经配置好服务器了!
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
Tomcat:
D:\dotNet.J2EE\jakarta-tomcat-5.5.9\conf
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
然后,启动 Java Web Application Server:
Resin:
D:\dotNet.J2EE\resin-2.1.16\bin\httpd.exe
Tomcat:
(启动 Tomcat 要预先配置 JAVA_HOME 环境变量)
D:\dotNet.J2EE\jakarta-tomcat-5.5.9\bin\start.bat
2.编写 Java Web Service 程序:
其实实现 Web Service 的 Java 类没啥特殊的,
下面程序就是:
实现支持文件分块多点异步上传的 Java Web Services (Server Side)//=========================================================================
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
//=========================================================================
如果上面程序存为: Class1.jws 文件,直接复制到:
D:\dotNet.J2EE\resin-2.1.16\webapps\axis\Class1.jws
或
D:\dotNet.J2EE\jakarta-tomcat-5.5.9\webapps\axis\Class1.jws
即可通过 IE 直接访问如下 URL 地址:
http://localhost:1080/axis/Class1.jws
这就如同 .Net Web Service .asmx 的前代码方式
接下来着重介绍一下定制部署 Java Web Service
将上面程序存为: Class1.java 文件,并用如下命令行编译:
javac.exe Class1.java
生成的 Class1.class 文件复制到:
D:\dotNet.J2EE\resin-2.1.16\webapps\axis\WEB-INF\classes\Class1.class
或
D:\dotNet.J2EE\jakarta-tomcat-5.5.9\webapps\axis\WEB-INF\classes\Class1.class
编写部署文件
deploy.wsdd (undeploy.wsdd): 在通过如下命令行部署该 Web Service ,此时 Java Web Application Server 应已经运行:
java -cp %axis_lib%;%classpath%;. org.apache.axis.client.AdminClient deploy.wsdd -p1080
如果部署成功屏幕将会输出:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
如果在 Resin 上部署失败,可在:
D:\Resin\resin-2.1.16\conf\resin.conf
中:
Tomcat 上暂没发现上面部署失败问题!
部署成功后,在下面文件:
D:\dotNet.J2EE\resin-2.1.16\webapps\axis\WEB-INF\server-config.wsdd
或
D:\dotNet.J2EE\jakarta-tomcat-5.5.9\webapps\axis\WEB-INF\server-config.wsdd
中,已经被自动添加如下配置:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
当然也可以手工直接填写配置 server-config.wsdd 而不使用命令行工具!
至此如不出意外 java Web Service 已经部署完毕!
Client Side:
http://localhost:1080/axis/services/Class1Service?wsdl
已经可以正常访问!
java Client:
还可以用解压 axis-bin-1_2_1.zip 后:
D:\dotNet.J2EE\axis-bin-1_2_1\axis-1_2_1\samples\client\DynamicInvoker.java
用如下命令行编译后:
javac -cp %classpath%;%axis_lib%;. -Xlint:unchecked DynamicInvoker.java
生成 DynamicInvoker.class,
再如下命令行运行:
java -cp %axis_lib%;%classpath%;. DynamicInvoker http://localhost:1080/axis/services/Class1Service?wsdl SayHelloTo 小平
其中 %axis_lib% 为环境变量! 其中 %classpath% 为环境变量!
测试如果正常则输出:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
.Net Client:
先用如下命令生成代理类的程序 C# 代码:
% Visual Studio .Net 2003 安装目录下的 %\SDK\v1.1\Bin\wsdl.exe
具体命令行如下:
wsdl.exe /l:CS /out:Class1ServiceProxy.cs http://localhost:1080/axis/services/Class1Service?wsdl
然后用如下命令编译生成程序集: Class1ServiceProxy.dll
csc /t:library Class1ServiceProxy.cs 然后用如下命令编译生成程序集: Class1ServiceClient.exe
csc Class1ServiceClient.cs /r:Class1ServiceService.dll
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)