WebService(七)Java发布并调用

使用版本:

eclipse:eclipse-jee-kepler-R-win32.zip
JDK:jdk-7u25-windows-i586.exe j2sdk1.4.2_06.rar
Myeclipse:myeclipse-8.5.0-win32.exe
Tomcat:apache-tomcat-7.0.42-windows-x86.zip apache-tomcat-5.0.12.zip
Axis2:axis2-1.6.2-bin.zip axis2-1.6.2-war.zip axis2-eclipse-codegen-plugin-1.6.2.zip axis2-eclipse-service-plugin-1.6.2.zip
Axis1:axis-1.4.rar
WebLogic:oepe-indigo-installer-12.1.1.0.1.201203120349-12.1.1-win32.exe
Spring:spring-framework-3.1.1.RELEASE-with-docs.zip
Hibernate:hibernate-distribution-3.6.10.Final-dist.zip
Structs2;struts-2.3.15.1-all.zip
SVN:eclipse-svnplugin(subclipse site-1.6.2)
Oracle9i:Oracle 9i Disk1.iso Oracle 9i Disk2.iso Oracle 9i Disk3.iso

一、WS服务端工作流程

  • 监听网络端口(监听服务端口);
  • 接收客户端请求(接收SOAP请求);
  • 解析客户端请求(解析SOAP消息,将SOAP消息转换为数据对象);
  • 调用业务逻辑 (调用Web Service实现类的特定操作,参数是由SOAP消息 转换而来的数据对象);
  • 生成响应 (将返回值转换为SOAP消息);
  • 返回响应 (返回SOAP响应);
  • Webservice客户端工作流程:
  • 构造SOAP请求消息(将本地数据对象转换为SOAP消息);
  • 发送SOAP消息到Web Service服务器的指定端口
  • 接收SOAP响应消息;
  • 将SOAP响应消息转换为本地数据对象;

二、服务端

2.1 新建Dynamic Web Project

package com.service;

public class Calculator {
	public int add(int a, int b) {
		return (a + b);
	}

	public int subtract(int a, int b) {
		return (a - b);
	}

	public int multiply(int a, int b) {
		return (a * b);
	}

	public int divide(int a, int b) {
		return (a / b);
	}
}

2.2 发布

生成了相关的wsdl和wsdd文件。Wsdl文件对外描述本webservice的相关信息,外部系统可以通过该文件建立客户端来调用该文件对应的webservice。Wsdd文件则是webservice的部署配置文件。

三、调用

通过eclipse内置的webservice explorer来对webservice进行调用测试。

四、客户端

package com.client;

import com.service.CalculatorProxy;

public class CalculatorTest {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		CalculatorProxy calculatorProxy = new CalculatorProxy();
		try {
			int result = calculatorProxy.add(4, 2);
			System.out.println("the result is:" + result);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

发表回复