Webservice-使用Tomcat的SOAP的应用
2008-04-17 18:12
330 查看
Web Services 可以将应用程序转换为网络应用程序。
通过使用 Web Services,您的应用程序可以向全世界发布信息,或提供某项功能。
Web Services 可以被其他应用程序使用。
通过 Web Services,您的会计部门的 Win 2k 服务器可以与 IT 供应商的 UXIX 服务器相连接。
基本的 Web Services 平台是 XML+HTTP。
Web services 使用 XML 来编解码数据,并使用 SOAP 来传输数据。
参考文献及推荐阅读:
http://dev.rdxx.com/Java/WebService/2005-07/27/102648552.shtml http://www.onjava.com/pub/a/onjava/2002/02/27/tomcat.html?page=1
1 下载SOAP
http://apache.mirror.phpchina.com/ws/axis/1_4/axis-bin-1_4.zip
2 xerces
http://xml.apache.org/dist/xerces-j/Xerces-J-bin.2.9.1.zip
3 JavaMail
http://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/VerifyItem-Start/javamail-1_4_1.zip?BundledLineItemUUID=9p5IBe.pm1wAAAEZgx8LhFpM&OrderID=G6xIBe.pZPgAAAEZdh8LhFpM&ProductID=3v_ACUFBMTsAAAEYxBQ5AXuF&FileName=/javamail-1_4_1.zip
4 JSF(JavaBean Activation Framework)
http://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/VerifyItem-Start/jaf-1_1_1.zip?BundledLineItemUUID=d.JIBe.mX1cAAAEZvmRIclpM&OrderID=dDBIBe.mM7MAAAEZsWRIclpM&ProductID=zFnACUFBlVoAAAEYhxc5AXt.&FileName=/jaf-1_1_1.zip
http://127.0.0.1:8080/soap/servlet/rpcrouter
出现如下页面:
复制相关的*.jar进入Tomcat
D:/Tomcat/common/lib/soap.jar;
D:/Tomcat/common/lib/mail.jar;
D:/Tomcat/common/lib/xml-apis.jar;
D:/Tomcat/common/lib/activation.jar;
D:/Tomcat/common/lib/xercesImpl.jar
1 创建HelloWorldService.java
package onjava;
public class HelloWorldService
...{
public String getMessage()
...{
return "Hello World!";
}
}
2 HelloWorldClient.java
import java.io.*;
import java.util.*;
import java.net.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;
public class HelloWorldClient ...{
public static String DEFAULT_ENDPOINT = "http://localhost:8080/soap/servlet/rpcrouter";
public static void main(String args[]) throws Exception ...{
String endPoint = DEFAULT_ENDPOINT;
//Process Arguments
if (args.length == 1)
endPoint = args[0];
else if (args.length > 1)
System.out.println("java HelloWorldClient [endpoint]");
// Build the SOAP RPC request message using the Call object
Call call = new Call();
call.setTargetObjectURI("urn:onjavaserver");
call.setMethodName("getMessage");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
// Create a URL object, which represents the endpoint
URL url = new URL(endPoint);
// Send the SOAP RPC request message using invoke() method
Response resp = call.invoke(url, "");
// Check the response.
if (resp.generatedFault()) ...{ // Error Occured
Fault fault = resp.getFault();
System.out.println("The Following Error Occured: ");
System.out.println(" Fault Code = " + fault.getFaultCode());
System.out.println(" Fault String = " + fault.getFaultString());
} else ...{ // Completed Successfully
Parameter result = resp.getReturnValue();
System.out.println(result.getValue());
}
}
}
3 Tomcat下的配置:
运行:
java HelloWorldClient
Hello World!
注:D:/Tomcat/webapps/soap/WEB-INF/classes/onjava目录下存放HelloWorldService.class
通过使用 Web Services,您的应用程序可以向全世界发布信息,或提供某项功能。
Web Services 可以被其他应用程序使用。
通过 Web Services,您的会计部门的 Win 2k 服务器可以与 IT 供应商的 UXIX 服务器相连接。
基本的 Web Services 平台是 XML+HTTP。
Web services 使用 XML 来编解码数据,并使用 SOAP 来传输数据。
参考文献及推荐阅读:
http://dev.rdxx.com/Java/WebService/2005-07/27/102648552.shtml http://www.onjava.com/pub/a/onjava/2002/02/27/tomcat.html?page=1
1 下载SOAP
http://apache.mirror.phpchina.com/ws/axis/1_4/axis-bin-1_4.zip
2 xerces
http://xml.apache.org/dist/xerces-j/Xerces-J-bin.2.9.1.zip
3 JavaMail
http://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/VerifyItem-Start/javamail-1_4_1.zip?BundledLineItemUUID=9p5IBe.pm1wAAAEZgx8LhFpM&OrderID=G6xIBe.pZPgAAAEZdh8LhFpM&ProductID=3v_ACUFBMTsAAAEYxBQ5AXuF&FileName=/javamail-1_4_1.zip
4 JSF(JavaBean Activation Framework)
http://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/VerifyItem-Start/jaf-1_1_1.zip?BundledLineItemUUID=d.JIBe.mX1cAAAEZvmRIclpM&OrderID=dDBIBe.mM7MAAAEZsWRIclpM&ProductID=zFnACUFBlVoAAAEYhxc5AXt.&FileName=/jaf-1_1_1.zip
http://127.0.0.1:8080/soap/servlet/rpcrouter
出现如下页面:
SOAP RPC Router
Sorry, I don't speak via HTTP GET- you have to use HTTP POST to talk to me.复制相关的*.jar进入Tomcat
D:/Tomcat/common/lib/soap.jar;
D:/Tomcat/common/lib/mail.jar;
D:/Tomcat/common/lib/xml-apis.jar;
D:/Tomcat/common/lib/activation.jar;
D:/Tomcat/common/lib/xercesImpl.jar
1 创建HelloWorldService.java
package onjava;
public class HelloWorldService
...{
public String getMessage()
...{
return "Hello World!";
}
}
2 HelloWorldClient.java
import java.io.*;
import java.util.*;
import java.net.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;
public class HelloWorldClient ...{
public static String DEFAULT_ENDPOINT = "http://localhost:8080/soap/servlet/rpcrouter";
public static void main(String args[]) throws Exception ...{
String endPoint = DEFAULT_ENDPOINT;
//Process Arguments
if (args.length == 1)
endPoint = args[0];
else if (args.length > 1)
System.out.println("java HelloWorldClient [endpoint]");
// Build the SOAP RPC request message using the Call object
Call call = new Call();
call.setTargetObjectURI("urn:onjavaserver");
call.setMethodName("getMessage");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
// Create a URL object, which represents the endpoint
URL url = new URL(endPoint);
// Send the SOAP RPC request message using invoke() method
Response resp = call.invoke(url, "");
// Check the response.
if (resp.generatedFault()) ...{ // Error Occured
Fault fault = resp.getFault();
System.out.println("The Following Error Occured: ");
System.out.println(" Fault Code = " + fault.getFaultCode());
System.out.println(" Fault String = " + fault.getFaultString());
} else ...{ // Completed Successfully
Parameter result = resp.getReturnValue();
System.out.println(result.getValue());
}
}
}
3 Tomcat下的配置:
Deployed Service Information
'urn:onjavaserver' Service Deployment Descriptor | |
---|---|
Property | Details |
ID | urn:onjavaserver |
Scope | Application |
Provider Type | java |
Provider Class | onjava.HelloWorldService |
Use Static Class | false |
Methods | getMessage |
Type Mappings | |
Default Mapping Registry Class |
java HelloWorldClient
Hello World!
注:D:/Tomcat/webapps/soap/WEB-INF/classes/onjava目录下存放HelloWorldService.class
相关文章推荐
- Webservice-使用Tomcat的SOAP的应用
- java使用soap方式简单实现webservice
- C#使用SOAP获取webservice实例解析
- Node.js 使用 soap 模块请求 WebService 服务接口
- WebService大讲堂之Axis2(10):使用soapmonitor模块监视soap请求与响应消息
- 使用Visual C++开发SOAP客户端应用
- 使用myeclipse插入数据到mysql 出现中文乱码|utf8乱码解决方案[适合tomcat部署的jsp应用]
- PHP使用SOAP调用.net的WebService问题
- 打包一个使用SOAP应用的客户端需要什么?
- 【Java Web】: 使用Tomcat与MyEclipse搭建Web应用及其相关的配置
- PHP使用SOAP调用.net的WebService数据
- WebService开发(二) 如何使用Soap扩展
- 使用acegi security +spring +mysql+ tomcat搭应用过程
- 使用php webservice(SOAP)的注意事项
- 使用ksoap2-android调用WebService 在Android中应用
- 使用 RemObjects SDK 建立 WebService 应用
- 使用ADF BC AM创建SOAP WebService
- 使用webpy创建一个简单的restful风格的webservice应用
- WebService 应用- .Net 平台WebService的创建、部署和使用介绍(转)
- 使用Ant发布web应用到tomcat