Java调用wsdl,怎么实现? 我知道怎么用Java函数来创建wsdl文件,就是想问一下有了wsdl文件,怎么用Java函数(类、方法)去调用它?怎么用jsp调用这个wsdl?期望各位大侠能做一下指导! 很急!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 对wsdl不了解,顶,学习一下! wsdl据说是开发语言之间的翻译,很牛的 导入axis的八个包:axis.jarcommons-discovery.jarcommons-logging.jarjaxrpc.jarsaaj.jarwsdl4j.jar axis-ant.jarlog4j-1.2.8.jar开发客户端程序。开发客户端程序的项目中要加入axis.jar包。文件:TestWebService.javaimport org.apache.axis.client.Call;import org.apache.axis.client.Service;import org.apache.axis.encoding.XMLType;public class TestWebService {public static void main(String[] args) { try { //还记得刚才的那个WebService的services.xml中的namespace吗? String endpoint = "http://localhost:8080/uum/services/Hello.jws?wsdl"; Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress(new java.net.URL(endpoint)); call.setOperationName("GetName"); // 这里是的Hello类中的方法名(注意大小写) call.setReturnType(XMLType.XSD_STRING); // 返回值类型。 call.addParameter("name",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN); String[] str= {"张三"}; Object[] o = str; //Object[] o =null;//如果你的方法中没有参数,那么就这样写吧。 String hello = (String) call.invoke(o);// 做方法执行。 System.out.println(hello); } catch (Exception e) { System.err.println(e.toString()); } }}执行这段代码,将会在命令行中输出 “hello 张三”,表示测试成功。Axis下载地址为http://ws.apache.org/axis/ 用Axis开发Web Service,我刚用过,很好用的,好好学学吧! 这个是WEB SERVISE 的调用,你的IDE能自动生成代码的,然后再调用 用代码怎么调用呢创建了Service ser=new Service()Cell c=ser.creatCell();c.setTargetEndpointAddress("wsdl的地址");怎么知道它的返回值呢。 WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();definition = wsdlReader.readWSDL(wsdlPath);Map services = definition.getServices();Types types = (TypesImpl) definition.getTypes();while(portsIter.hasNext()){PortImpl port = (PortImpl) portsIter.next();List bindingOperations = port.getBinding().getBindingOperations();if(bindingOperations.size() ==1 ){ CreateWSDLOperation((BindingOperation) bindingOperations.get(0)); wsdlOperation.setSoapAddress(getSopaAddress(port));}private String getSopaAddress(Port port){ String soapAddress = ""; List address = port.getExtensibilityElements(); if (port.getExtensibilityElements().size() == 1) { SOAPAddress element = (SOAPAddress) address .get(0); soapAddress = element.getLocationURI() ; } return soapAddress ; } 如何在web端隐藏google地图的经纬度 数据库里的二进制图片读取的问题 请求大家解答一下 java图表控件 hibernate,spring配置异常 编译总是出错,大家帮忙看一下!!cannot find symbol 小弟新手,struts+hibernate弄个登陆的问题,求解 关于日期转换 从数据库中取出的图片字节,如何显示到一个页面当中? 关于多个表单提交到一个SERVLET的问题。 请教,Servlet 容器与Web容器的区别? 我做项目时,用ssh时出的错,看不懂啊,大侠们帮帮忙啊 面试题如何做比较简单?关于时间的!
axis.jar
commons-discovery.jar
commons-logging.jar
jaxrpc.jar
saaj.jar
wsdl4j.jar
axis-ant.jar
log4j-1.2.8.jar
开发客户端程序。开发客户端程序的项目中要加入axis.jar包。
文件:TestWebService.java
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
public class TestWebService {
public static void main(String[] args) {
try {
//还记得刚才的那个WebService的services.xml中的namespace吗?
String endpoint = "http://localhost:8080/uum/services/Hello.jws?wsdl";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName("GetName"); // 这里是的Hello类中的方法名(注意大小写)
call.setReturnType(XMLType.XSD_STRING); // 返回值类型。
call.addParameter("name",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
String[] str= {"张三"};
Object[] o = str;
//Object[] o =null;//如果你的方法中没有参数,那么就这样写吧。
String hello = (String) call.invoke(o);// 做方法执行。
System.out.println(hello);
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
执行这段代码,将会在命令行中输出 “hello 张三”,表示测试成功。
Axis下载地址为http://ws.apache.org/axis/
Cell c=ser.creatCell();
c.setTargetEndpointAddress("wsdl的地址");
怎么知道它的返回值呢。
definition = wsdlReader.readWSDL(wsdlPath);
Map services = definition.getServices();
Types types = (TypesImpl) definition.getTypes();
while(portsIter.hasNext()){
PortImpl port = (PortImpl) portsIter.next();
List bindingOperations = port.getBinding().getBindingOperations();
if(bindingOperations.size() ==1 ){
CreateWSDLOperation((BindingOperation) bindingOperations.get(0));
wsdlOperation.setSoapAddress(getSopaAddress(port));
}
private String getSopaAddress(Port port){
String soapAddress = "";
List address = port.getExtensibilityElements();
if (port.getExtensibilityElements().size() == 1) {
SOAPAddress element = (SOAPAddress) address
.get(0);
soapAddress = element.getLocationURI() ;
}
return soapAddress ;
}