Topic: Apache SOAP的Web Services在Tomcat上的初体验:安装和测试

  Print this page

1.Apache SOAP的Web Services在Tomcat上的初体验:安装和测试 Copy to clipboard
Posted by: YuLimin
Posted on: 2005-01-23 15:30

Apache SOAP的Web Services在Tomcat上的初体验:安装和测试

下载:
Apache SOAP  http://xml.apache.org/soap/index.html
Tomcat    http://jakarta.apache.org/

1、解压Apache SOAP到%ApacheSOAP%,如:F:\OpenSource\SOAP

2、安装Tomcat到%Tomcat%,如:F:\Program Files\Apache Group\Tomcat

3、复制%ApacheSOAP%\webapps\soap.war文件到%Tomcat%\webapps目录下

4、启动Tomcat,此时Tomcat自动将soap.war解压了

5、在%Tomcat%\webapps\soap\WEB-INF\classes建立测试文件HelloSOAPClient.java、HelloSOAP.java,源码附后

6、编译,进入%Tomcat%\webapps\soap\WEB-INF\classes目录
  javac -classpath .;%classpath%;F:\OpenSource\SOAP\lib\soap.jar *.java

7、SOAP服务的发布
  使用IE浏览器浏览http://localhost:8080/soap/admin/index.html,进入Deploy,填写如下信息:
  ID: urn:hello.hellosoap
  Scope: Request
  Methods getWelcomeValue
  Provider Type: Java
  Java Provider Provider Class: HelloSOAP
  Java Provider Static: NO
  确认发布,可以点List查看已发布服务
Service Listing
Here are the deployed services (select one to see details)

urn:hello.hellosoap

8、运行,java -classpath .;%classpath%;F:\OpenSource\SOAP\lib\soap.jar HelloSOAPClient
  可以看到返回值信息如下:
SOAP调用测试开始。。。
Name:俞黎敏
Result:欢迎光临SOAP:俞黎敏
SOAP调用测试结束。。。

则证明配置和测试成功,以后就可以发布自己的SOAP服务了!

9、删除服务Un-deploy之即可
Un-Deploy a Service
Select the service to be undeployed:

urn:hello.hellosoap

public class HelloSOAP
{
public String getWelcomeValue(String name)
{
String strResult = "欢迎光临SOAP:" + name;
return strResult;
}
}

import java.net.URL;
import java.util.Vector;

import org.apache.soap.Constants;
import org.apache.soap.Fault;
import org.apache.soap.rpc.Call;
import org.apache.soap.rpc.Parameter;
import org.apache.soap.rpc.Response;

public class HelloSOAPClient
{
public static void main(String[] args) throws Exception
{
System.out.println("SOAP调用测试开始。。。");
String name = "俞黎敏";
HelloSOAPClient helloSOAPClient = new HelloSOAPClient();
//调用远程的SOAP服务
String resultValue = helloSOAPClient.doSOAPRequest("hello.hellosoap","getWelcomeValue","name",name);
System.out.println("Name:" + name);
System.out.println("Result:" + resultValue);
System.out.println("SOAP调用测试结束。。。");
}

public String doSOAPRequest(String _strURI,String _strMethodName,String _strName,String _strValue) throws Exception
{
//创建一个远程调用
Call call = new Call();
//设置远程对象的URI
call.setTargetObjectURI("urn:" + _strURI);
//设置调用的方法名
call.setMethodName(_strMethodName);
//设置编码风格
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
//设置方法调用的参数
Vector params = new Vector();
params.addElement(new Parameter(_strName,String.class,_strValue,null));
call.setParams(params);
//发送RPC请求,请查看webapps\soap\web.xm,就知道rpcrouter是映射到org.apache.soap.server.http.RPCRouterServlet这个类
Response resp = call.invoke(new URL("http://localhost:8080/soap/servlet/rpcrouter"),"");
if(resp.generatedFault())
{
//远程调用出错处理
Fault fault = resp.getFault();
System.out.println("调用失败!");
System.out.println("错误代号:" + fault.getFaultCode());
System.out.println("错误信息:" + fault.getFaultString());
return "调用失败!";
}
else
{
//调用成功,获取返回值
Parameter result = resp.getReturnValue();
return result.getValue().toString();
}
}
}

2.Re:Apache SOAP的Web Services在Tomcat上的初体验:安装和测试 [Re: YuLimin] Copy to clipboard
Posted by: phoenixup
Posted on: 2005-04-12 17:08

好文章,知识在实践中,才会有较深的理解!

3.Re:Apache SOAP的Web Services在Tomcat上的初体验:安装和测试 [Re: YuLimin] Copy to clipboard
Posted by: xiaoyun5109
Posted on: 2005-04-19 17:43

Post is deleted

4.Re:Apache SOAP的Web Services在Tomcat上的初体验:安装和测试 [Re: xiaoyun5109] Copy to clipboard
Posted by: YuLimin
Posted on: 2005-04-20 00:43

SOAP已经停止开发了,用AXIS

Apache Axis is an implementation of the SOAP ("Simple Object Access Protocol") submission to W3C.

From the draft W3C specification:

SOAP is a lightweight protocol for exchange of information in a decentralized, distributed environment. It is an XML based protocol that consists of three parts: an envelope that defines a framework for describing what is in a message and how to process it, a set of encoding rules for expressing instances of application-defined datatypes, and a convention for representing remote procedure calls and responses.

5.Re:Apache SOAP的Web Services在Tomcat上的初体验:安装和测试 [Re: YuLimin] Copy to clipboard
Posted by: stonezhu
Posted on: 2005-06-25 12:20

好样的.我喜欢.这样的文章应该多发啊 .

6.Re:Apache SOAP的Web Services在Tomcat上的初体验:安装和测试 [Re: stonezhu] Copy to clipboard
Posted by: why
Posted on: 2005-06-25 18:39

請問這是原創還是轉貼的?

7.Re:Apache SOAP的Web Services在Tomcat上的初体验:安装和测试 [Re: YuLimin] Copy to clipboard
Posted by: gmmylose
Posted on: 2005-07-16 18:13

运行有异常,郁闷

8.Re:Apache SOAP的Web Services在Tomcat上的初体验:安装和测试 [Re: YuLimin] Copy to clipboard
Posted by: gmmylose
Posted on: 2005-07-16 21:00

OK了,谢谢楼主文章,很不错的入门文章,


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923