「javawebservice」java webservice接口开发教程
今天给各位分享javawebservice的知识,其中也会对java webservice接口开发教程进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
Java调用webservice和postmain调用的区别
区别是WebService可以有Get、Post、Soap、Document四种方式调用。
我们可以把webservice看做是web服务器上的一个应用,web服务器是webservice的一个容器。通过wximport生成代码。通过客户端编程方式。
通过URLConnection方式调用。
java如何调用webservice接口?
Java通过WSDL文件来调用webservice直接调用模式如下:
import java.util.Date;
import java.text.DateFormat;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
import java.lang.Integer;
import javax.xml.rpc.ParameterMode;
public class caClient {
public static void main(String[] args) {
try {
String endpoint = "";
//直接引用远程的wsdl文件
//以下都是套路
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);
call.setOperationName("addUser");//WSDL里面描述的接口名称
call.addParameter("userName", org.apache.axis.encoding.XMLType.XSD_DATE,
javax.xml.rpc.ParameterMode.IN);//接口的参数
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//设置返回类型
String temp = "测试人员";
String result = (String)call.invoke(new Object[]{temp});
//给方法传递参数,并且调用方法
System.out.println("result is "+result);
}
catch (Exception e) {
System.err.println(e.toString());
}
}
}
java webservice怎么生成wsdl文件
在大多数情况下我们都需要为我们的服务提供一个WSDL文件,而 Axis2's Java2WSDL 是专门用来生成WSDL文件的D专用工具,如果你要在命令行模式下进行生成WSDL文件,首先需要保证你的环境变量AXIS2_HOME是否已经配置OK,同时还要保证把%AXIS2_HOME%\bin加入到你的path环境中,要生成 WSDL文件,首先要保证你的class能够编译成功,而且已经编译成功,然后进入class文件编译后的根目录(在JBuilder中是classes,在Eclipse中是bin目录)这时,生成WSDL文件的准备工作已经OK。\x0d\x0a\x0d\x0a下面是生成WSDL文件时的可选参数和参数说明:\x0d\x0a---------------------------------------------------------------------------------\x0d\x0aUsage java2wsdl -cn : class file name\x0d\x0a-o : output file location\x0d\x0a\x0d\x0a-cp : list of classpath entries - (urls)\x0d\x0a\x0d\x0a-tn : target namespace\x0d\x0a\x0d\x0a-tp : target namespace prefix\x0d\x0a\x0d\x0a-stn : target namespace for schema\x0d\x0a\x0d\x0a-stp : target namespace prefix for schema\x0d\x0a\x0d\x0a-sn : service name\x0d\x0a\x0d\x0a-of : output file name for the WSDL\x0d\x0a\x0d\x0a-st : style for the WSDL\x0d\x0a\x0d\x0a-u : use for the WSDL\x0d\x0a\x0d\x0a-l : address of the port for the WSDL\x0d\x0a\x0d\x0a-nsg : fully qualified name of the class that implements NamespaceGenerator\x0d\x0a\x0d\x0a-p2n [,,] ...\x0d\x0a\x0d\x0a-efd : Setting for elementFormDefault (defaults to qualified)\x0d\x0a\x0d\x0a-afd : Setting for attributeFormDefault (defaults to qualified)\x0d\x0a\x0d\x0a-xc : Extra class for which schematype must be generated.\x0d\x0aUse as : -xc class1 -xc class2 ...\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a典型地,进入你的工程的二进制编译根目录,执行命令模板如下:\x0d\x0ajava2wsdl -cp . -cn [PACKAGENAME].[CLASSNAME]-of [FILENAME].wsdl\x0d\x0a\x0d\x0a现在我们假设在samples.helloworld.service.axiom;包下面有个HelloWorldService类,工程的类文件编译后存放在build\classes目录下,那么,首先进入该目录中,然后执行以下命令:\x0d\x0ajava2wsdl -cp . -cn samples.helloworld.service.axiom.HelloWorldService -of HelloWorldService.wsdl\x0d\x0a\x0d\x0a执行后的CMD提示如下说明已经成功执行了:\x0d\x0a\x0d\x0aUsing AXIS2_HOME: D:\axis2-1.1.1\x0d\x0aUsing JAVA_HOME: C:\Program Files\Java\jdk1.5.0_06
javawebservice的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java webservice接口开发教程、javawebservice的信息别忘了在本站进行查找喔。