生成验证码的wsdl:http://www.webxml.com.cn/WebServices/ValidateCodeWebService.asmx?wsdl
首先在浏览器上访问是否可以访问到如图这样就是可以访问
在eclipse/myeclipse中创建一个项目
ctrl+n创建webservice客户端
详细代码:
package cn.com.test;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import cn.com.WebXml.ValidateCodeWebServiceLocator;
import cn.com.WebXml.ValidateCodeWebServiceSoap;
public class Test {
public static void main(String[] args) throws Exception {
ValidateCodeWebServiceLocator v = new ValidateCodeWebServiceLocator();
ValidateCodeWebServiceSoap vv = v.getValidateCodeWebServiceSoap();
//vv.cnValidateImage("44577775");
byte[] enValidateByte = vv.enValidateByte("12aS5r7F");
String imgPath="E:\\";
String imgName="1.png";
get(imgPath, imgName, enValidateByte);
byte[] cnValidateByte = vv.cnValidateByte("123eDfr78");
get(imgPath, "2.png", cnValidateByte);
get(imgPath, "3.png", vv.smallValidateByte("12fdjFs"));
System.out.println("生成完毕");
}
public static void get(String imgPath,String imgName,byte[] imgByte) throws Exception {
InputStream in = new ByteArrayInputStream(imgByte);
File file=new File(imgPath,imgName);//可以是任何图片格式.jpg,.png等
FileOutputStream fos=new FileOutputStream(file);
byte[] b = new byte[1024];
int nRead = 0;
while ((nRead = in.read(b)) != -1) {
fos.write(b, 0, nRead);
}
fos.flush();
fos.close();
in.close();
}
}
或许需要mail.jar activation.jar
下载 http://www.cppblog.com/Files/wform/mail-activation.rar
验证结果:
其他的webservices,如天气、邮箱、英汉互译等,都可以这样操作