AXIS通过wsdl2java程序调用Gsoap发布的服务
Gsoap 生成的服务见 以前写的文章。
--》add.wsdl
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="add"
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/">
<types>
<schema targetNamespace="urn:add"
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">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/"/>
<!-- operation request element -->
<element name="add">
<complexType>
<sequence>
<element name="num1" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__add::num1 -->
<element name="num2" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__add::num2 -->
</sequence>
</complexType>
</element>
<!-- operation response element -->
<element name="addResponse">
<complexType>
<sequence>
<element name="sum" type="xsd:int" minOccurs="0" maxOccurs="1" nillable="true"/><!-- ns__add::sum -->
</sequence>
</complexType>
</element>
</schema>
</types>
<message name="addRequest">
<part name="parameters" element="ns:add"/><!-- ns__add::ns__add -->
</message>
<message name="addResponse">
<part name="parameters" element="ns:addResponse"/>
</message>
<portType name="addPortType">
<operation name="add">
<documentation>Service definition of function ns__add</documentation>
<input message="tns:addRequest"/>
<output message="tns:addResponse"/>
</operation>
</portType>
<binding name="add" type="tns:addPortType">
<SOAP:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="add">
<SOAP:operation soapAction=""/>
<input>
<SOAP:body parts="parameters" use="literal"/>
</input>
<output>
<SOAP:body parts="parameters" use="literal"/>
</output>
</operation>
</binding>
<service name="add">
<documentation>gSOAP 2.8.3 generated service definition</documentation>
<port name="add" binding="tns:add">
<SOAP:address location="http://localhost/add.cgi"/>
</port>
</service>
</definitions>
--》新建批处理 通过 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
分享到:
相关推荐
axis2根据wsdl生成java客户端代码 D:\Software\axis2-1.6.2\bin>wsdl2java.bat -uri http://10.33.30.216:9099/facs/services/ResourceSynchroWebService?wsdl -o E:\wsdloutput -p com.util wsdl2java.bat -uri ...
抛出无法找到主类:org.apache.axis.wsdl.WSDL2Java(Throws Could not find main class: org.apache.axis.wsdl.WSDL2Java)。 添加本文的jar包压缩包解压出来的所有jar包到当前使用的java.exe 命令的lib目录下的ext...
axis2 wsdl2java的使用说明和简单程序.docx
Axis 把WSDL生成JAVA类Axis 把WSDL生成JAVA类Axis 把WSDL生成JAVA类Axis 把WSDL生成JAVA类Axis 把WSDL生成JAVA类Axis 把WSDL生成JAVA类Axis 把WSDL生成JAVA类Axis 把WSDL生成JAVA类Axis 把WSDL生成JAVA类
调用WSDL2Java需要相关jars,使用-cp添加进来,不支持使用通配符。提醒:Linux下jar之间使用冒号隔开:,windows下jar之间使用分号隔开 调用方法 java -cp mail-1.4.jar;saaj-api-1.3.jar;jaxrpc-1.1.jar;commons-...
java调用WebServices,jar报及帮助文档。文档为英文版。
wsdl2java工具 修改WSDL2Java(URL).bat后直接双击运行即可 编辑 WSDL2Java(URL).bat set Axis_Lib=.\lib //引用包 set Java_Cmd=java -Djava.ext.dirs=%Axis_Lib% set Output_Path=.\source //输出目录 set Package...
本案例实现使用Axis2生成.arr包发布WebService服务,并使用Axis2生成客户端代码方式调用WebService
wsdl2java.bat使用方法 wsdl2java包 axis所有的包
NULL 博文链接:https://747017186.iteye.com/blog/2371155
axis和axis2的一些发布差异(WSDL2Java) 收藏axis和axis2的一些发布差异(WSDL2Java) 收藏axis和axis2的一些发布差异(WSDL2Java) 收藏axis和axis2的一些发布差异(WSDL2Java) 收藏
NULL 博文链接:https://hck.iteye.com/blog/1683563
1、下载WSDL2JAVA.rar包,其中包含activation.jar,axis-ant.jar,axis.jar,commons- discovery-0.2.jar,commons-logging-1.0.4.jar,jaxrpc.jar,log4j- 1.2.8.jar,mail.jar,saaj.jar,wsdl4j-1.5.1.jar。...
java axis 调用 wsdl 所需要的jar,包含(javax.wsdl、commons-logging、commons-discovery-0.2、axis-1.4、activation、jaxrpc、mail、fastjson-1.1.37)
Java调用WSDLJava调用WSDLJava调用WSDLJava调用WSDLJava调用WSDLJava调用WSDLJava调用WSDLJava调用WSDL
使用cxf wsdl2java生成webservice客户端命令
基于 Apache Axis2 将上述类的方法对外提供 Web 服务,生成 WSDL 文件,以及调用 服务 2019-12-23根据全网的教程搭建最详细的教程 源码太大上传不了,但是教程内容十分详细,跟着我的教程一步一步就可以搭建起来,...
使用Java+Axis2调用Web Services 网络接口,代码中列举4个例子可以查看,有详细注释提供参考。
使用axis将wsdl文件转换为java代码
webserice开发工具。Axis2不仅支持SOAP1.1和SOAP1.2,还集成了非常流行的REST WebService,同时还支持Spring、JSON等技术。