当前位置:我的异常网» XML/SOAP » AXIS经过wsdl2java程序调用Gsoap发布的服务
AXIS经过wsdl2java程序调用Gsoap发布的服务
www.myexceptions.net 网友分享于:2013-11-10 浏览:44次
AXIS通过wsdl2java程序调用Gsoap发布的服务
AXIS通过wsdl2java程序调用Gsoap发布的服务
Gsoap 生成的服务见 以前写的文章。
--》add.wsdl
targetNamespace="http://localhost/add.wsdl"
xmlns:tns="http://localhost/add.wsdl"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns="urn:add"
xmlns:SOAP="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:MIME="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:DIME="http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/"
xmlns:WSDL="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns="urn:add"
xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="unqualified"
attributeFormDefault="unqualified">
Service definition of function ns__add
gSOAP 2.8.3 generated service definition
--》新建批处理 通过 wsdl2java 生成代码
set Axis_Lib=E:/mysoft/axis-1_4/lib
set Java_Cmd=java -Djava.ext.dirs=%Axis_Lib%
set Output_Path=E:/mysoft/axis-1_4/mytest
set Package=com.sf
%Java_Cmd% org.apache.axis.wsdl.WSDL2Java -o%Output_Path% -p%Package% add.wsdl
--》测试代码
/**
* 方式一 通过查看 wsdl 直接访问
*/
package com.sf;
import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class Test {
public static void main(String[] args) {
try {
String endpoint = "http://localhost:5555/?wsdl";
// 直接引用远程的wsdl文件
// 以下都是套路
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(new QName("urn:add", "add"));// WSDL里面描述的接口名称
call.addParameter("num1",
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);// 接口的参数
call.addParameter("num2",
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);// 接口的参数
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// 设置返回类型
Object[] c = { 6, 2 };
String result = (String) call.invoke(c);
// 给方法传递参数,并且调用方法
System.out.println("result is " + result);
}
catch (Exception e) {
System.err.println(e.toString());
}
}
}
/**
* 方式二 通过wsdl2java
*/
package com.sf;
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
public class Test2 {
public static void main(String[] args) throws MalformedURLException, ServiceException, RemoteException {
Add_Service service = new Add_ServiceLocator();
AddPortType client = service.getadd(new java.net.URL("http://localhost:5555/?wsdl")) ;
// AddPortType client = service.getadd() ;
int result = client.add(5,6);
System.out.println(result);
}
}
--》javaScript 测试
var call=new WS.Call(wsAddress);
var nsuri='urn:add';
var type_int=new WS.QName('int','http://www.w3.org/2000/10/XMLSchema');
var type_string=new WS.QName('string','http://www.w3.org/2000/10/XMLSchema');
var qn_op1=new WS.QName('add',nsuri);
//var qn_op1_resp=new WS.QName('getAttrTypeResponse',nsuri);
//top.add=add;
function add(num1,num2) {
call.invoke_rpc(
qn_op1
,new Array(
{name:'num1',value:num1,xsitype:type_int}
,{name:'num2',value:num2,xsitype:type_int}
)
,null
,function (call,envelope) {
var xbody=envelope.get_body().get_all_children()[0].get_all_children()[0].get_value();
// top.createMenuByString(xbody,x,y);
console.log(xbody);
}
)
}
--》下一步进行非基本类型数据交互
--》参考
Java调用以WSDL形式发布的web service .
http://blog.csdn.net/boy_wh520/article/details/1601756
使用AXIS调用WSDL描述的Web服务
http://www.blogjava.net/mrcold/archive/2009/06/17/220044.html
wsdl -axis-webservise(测试通过) .
http://blog.csdn.net/renhui15688/article/details/4261026
文章评论