快速开发 webservice服务端

本文介绍了如何使用集成的Java EE IDE快速创建并部署Webservice服务端。通过新建项目、定义WSDD、自动生成源代码,然后将项目导出为WAR文件,部署到Tomcat服务器上,实现Webservice服务端的发布。同时,文章还展示了如何生成并使用Webservice客户端进行调用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用集成软件java EE IDE

 新建一个项目

 新建wsdl

新建web service(选择刚才新建的wsdl),会自动生成源代码.

修改UploadSOAPImpl.java(见下面代码)

把这个项目export 成 *.WAR

放到tomcat的webapp中.启动tomcat.该webservice服务端发布成功.

打开http://127.0.0.1:70/uploadImg/services

显示如下:

 

public class UploadSOAPImpl implements org.example.www.Upload.Upload_PortType{
	
	  
    public boolean updateImage(String name, String image, int fid, int tid, String userid, String password, String title, String content) throws java.rmi.RemoteException {
		FileOutputStream fos = null;
		try {
			byte[] buffer = new BASE64Decoder().decodeBuffer(image);
			System.out.println(buffer.length);
			Date date = new Date();
			long s = date.getTime();
			fos = new FileOutputStream("d:/uploadimages/"+s+".jpg");
			fos.write(buffer);
			fos.flush();
			fos.close();
			return true;
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			// TODO: handle exception
		} catch (IOException e) {
			e.printStackTrace();
			// TODO: handle exception
		} finally {
			try {
				fos.flush();
				fos.close();
	
			} catch (Exception e) {
				e.printStackTrace();
				// TODO: handle exception
			}
		}
	
		return false;
	}


 新建webserviceClient.自动生成UploadProxy.java等

使用实例如下:

 

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.apache.axis.encoding.Base64;
import org.example.www.Upload.UploadProxy;

public class TestClient {
 public static void main(String[] args) throws Exception {
  UploadProxy up = new UploadProxy();
  up.setEndpoint("http://127.0.0.1:70/uploadImg/services/UploadImg");
  try {
   FileInputStream fis = new FileInputStream("d://1.jpg");
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   byte[] buffer = new byte[8192];
   int count = 0;
   while ((count = fis.read(buffer)) >= 0) {
    baos.write(buffer, 0, count);
   }
   String uploadBuffer = new String(Base64.encode(baos.toByteArray()));

   up.updateImage("", uploadBuffer, 0, 0, "", "", "", "");
   fis.close();
  } catch (FileNotFoundException e) {
   e.printStackTrace();
   // TODO: handle exception
  } catch (IOException e) {

   e.printStackTrace();
   // TODO: handle exception
  }

 }

}


 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值