Welcome 微信登录

首页 / 软件开发 / JAVA / WTP1.0开发WebService之Java Class实例

WTP1.0开发WebService之Java Class实例2011-02-16hangjunhd在创建web service 之前,确定你已经安装Tomcat。(本文使用Tomcat5.0)

1.创建一个动态web工程(dynamic web project)取名为ConverterProj。配置全部默认。

2.在package wtp下建立java文件Converter.java

Converter.java

package wtp;
public class Converter {
public float celsiusToFarenheit(float celsius){
return (celsius*9/5)+32;
}
public float farenheitToCelsius(float farenheit){
return (farenheit-32)*5/9;
}
}

注:

这里声明的方法的首字母必须小写,即如果使用CelsiusToFarenheit则会出错,信息如下。

exception: org.apache.axis.InternalException: java.lang.Exception: Couldn"t find a matching Java operation for WSDD operation " celsiusToFarenheit " (1 args)

The exception raised indicates that the reflection processes of the service are looking for method names that only start with lower case letters.

3.选择Converter.java,右键点击New-Other-Web Services-Web Service

配置如下图: