「javawsdl文档」java doc
今天给各位分享javawsdl文档的知识,其中也会对java doc进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
java web项目怎么使用wsdl文件
webservice的发布一般都是使用WSDL(web service descriptive language)文件的样式来发布的,在WSDL文件里面,包含这个webservice暴露在外面可供使用的接口。
注意,以下的代码并没有经过真正的测试,只是说明这些情况,不同版本的Axis相差很大,最好以apache网站上的例子为准,这里仅仅用于说明其基本用法。
1,直接AXIS调用远程的web service,直接调用模式如下:
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());
}
}
}
2,直接SOAP调用远程的webservice ,这种模式很少用,但是网络上有人贴出来,也转过来 :
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;
import java.io.*;
import java.net.*;
import java.util.Vector;
public class caService{
public static String getService(String user) {
URL url = null;
try {
url=new URL("");
} catch (MalformedURLException mue) {
return mue.getMessage();
}
// This is the main SOAP object
Call soapCall = new Call();
// Use SOAP encoding
soapCall.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
// This is the remote object we're asking for the price
soapCall.setTargetObjectURI("urn:xmethods-caSynrochnized");
// This is the name of the method on the above object
soapCall.setMethodName("getUser");
// We need to send the ISBN number as an input parameter to the method
Vector soapParams = new Vector();
// name, type, value, encoding style
Parameter isbnParam = new Parameter("userName", String.class, user, null);
soapParams.addElement(isbnParam);
soapCall.setParams(soapParams);
try {
// Invoke the remote method on the object
Response soapResponse = soapCall.invoke(url,"");
// Check to see if there is an error, return "N/A"
if (soapResponse.generatedFault()) {
Fault fault = soapResponse.getFault();
String f = fault.getFaultString();
return f;
} else {
// read result
Parameter soapResult = soapResponse.getReturnValue ();
// get a string from the result
return soapResult.getValue().toString();
}
} catch (SOAPException se) {
return se.getMessage();
}
}
}
java中wsdl文件怎么生成
原则上,你可以先把JAVA生成.net的文件,然后根据以下其中一个方法,转变为WSDL
在.NET中有三种方式生成WSDL:
1.在Web Service的URL后面加上WDSL需求,如下:
2.使用disco.exe。在命令行中写下如下的命令:
disco
3.使用System.Web.Services.Description命名空间下提供的类
每个 WSDL 文件的根元素都是 definitions,必须在其中提供服务的完整描述。首先,必须在 definitions 元素中提供各种名称空间的声明。
definitions 元素包含一个或多个 portType 元素,每个元素都是一系列 operation。可以将单个portType元素看作是将各种方法组成类的一个逻辑分组。应该将每个Types称为服务,因此整个 WSDL 文件将成为一个服务集合。
在每个服务内可以有几个方法或者 operation,WSDL 通过 operation 元素来引用它们。
下面是一个最简单的WSDL例子
?xml version="1.0" encoding="UTF-8" ?
definitions name="MobilePhoneService"
targetNamespace=""
xmlns=""
xmlns:soap=""
xmlns:tns=""
xmlns:xsd=""
portType name="MobilePhoneService_port"
operation name="getListOfModels "
.......
.......
/operation
operation name="getPrice"
.......
.......
/operation
/portType
/definitions
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
JAX-WS用什么命令从JAVA代码生成WSDL文档?
你好,使用java自带的wsgen命令生成wsdl文件,前提是需要开发机器上安装并配置好了java环境变量。
操作步骤如下:
在cmd下,切换到项目(wsproject)目录下,输入如下命令:D:\wsprojectwsgen -cp WebRoot/WEB-INF/classes/ -r WebRoot/WEB-INF/wsdl -s src -d WebRoot/WEB-INF/classes -wsdl name.zeal.service.MySrv
执行完毕后,会在WebRoot/WEB-INF/wsdl下生成两个文件:MySrvService.wsdl和MySrvService_schema1.xsd
如果接口客户端只能用一个wsdl文件,那就得使用内嵌模式的WSDL文件命令生成单个文件了。示例:D:\wsprojectwsgen -cp WebRoot\WEB-INF\classes\ -r WebRoot/WEB-INF/wsdl -s src -d WebRoot/WEB-INF/classes -wsdl -inlineSchemas name.zeal.service.MySrv
注意事项:如果要用到wsgen,则必须需要对Service实现的Java代码进行标注注解,否则wsgen无法识别到这是一个WebService
javawsdl文档的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java doc、javawsdl文档的信息别忘了在本站进行查找喔。