济南做平台网站的/软文推广经典案例
使用集成软件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
}
}
}