WebLogic环境下WebService开发过程
一.W ebService开发环境的创立
1.创立WebService工程
开发工具采用WebLogic自带的Wokshop开发
2.引入WebLogic下的webservices.jar包
该jar包位于WebLogic的安装路径下的weblogic92\server\lib目录,比方D:\bea\weblogic92\server\lib
3.创立WebService类
3.1创立类
3.2需要发布成WebService的类引入WebService的对应类
import java*.jws.*;
import weblogic.jws.WLHttpTransport;
import weblogic.jws.WSDL;
import java*.jws.soap.SOAPBinding;
import java*.*ml.namespace.QName;
import java*.*ml.rpc.soap.SOAPFaultE*ception;
import java*.*ml.soap.Detail;
import java*.*ml.soap.Name;
import java*.*ml.soap.SOAPE*ception;
import java*.*ml.soap.SOAPFactory;
3.3 通过添加注释将类及方法暴露为WebService接口
WebService 和WebMethod这两个标示是必须的
〔1〕添加类注释,比方:
WebService(name = "CrudTable", serviceName = "CrudTableService", targetNamespace = ".victorysoft.")
WLHttpTransport(serviceUri = "CrudTableService", portName = "CrudTableSoapPort")
WSDL(e*posed = true)
SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL)
〔2〕添加方法注释,比方:
WebMethod
WebResult(name = "crudDataFromTableResponse", targetNamespace = ".victorysoft.")
4.开发环境下WebLogic效劳器的配置
4.1效劳器视图
4.2效劳器配置
4.3开发环境下的发布
点击〞发布〞菜单
到对应的WSDL文件,在build/jws/weboutput/WEB-INF/目录下,比方CrudTableService.wsdl
到最下面的WSDL发布URL,比方localhost:7001/TableCrud/CrudTableService,然后在浏览器地址栏输入对应的地址如localhost:7001/TableCrud/CrudTableService"WSDL
如能看到容,则说明发布成功
5.WebService的打WAR包方法
和普通Web工程没啥区别
二.W ebService客户端开发环境的创立
客户端需要创立一个普通的java工程就可,需要用Ant生成客户端代理程序。
1.相关用户库的创立
创立用户库WebServiceClient,步骤点击“窗口〞—〉〞首选项〞—〉〞
java〞-->〞构建路径〞—〉“用户库〞
将weblogic.jar、webserviceclient.jar、apache*mlbeansutil.jar参加到
WebServiceClient用户库中
2.引入WebServiceClient用户库
3.Ant类库的配置
Ant的主路径参加weblogic.jar
点击“窗口〞—〉〞首选项〞—〉〞Ant〞-->“运行时“—〉〞类路径〞
—〞Ant主目录条目“—〉〞添加外部JAR“
4.Ant的bulid.*ml的配置
容如下:
<"*ml version="1.0" encoding="ISO-8859-1"">
<project name="SwAClient" default="all" basedir=".">
<!-- set global properties for this build -->
<property file="../e*amples.properties" />
<property name="src.dir" value="./src"/>
<property name="weblogic.home" value="D:/bea/weblogic92" />
<property name="generated.src.dir" value="./gen_src"/>
<property name="classes.dir" value="./bin" />
<property name="docs.dir" value="./docs" />如何生成webservice客户端
<property name="javadoc.dir" value="${docs.dir}/javadoc" />
<!-- The application conte*t on the server where this pro*y service is deployed -->
<property name="conte*t.path" value="CrudTableService" /> <property name="webservice.name" value="CrudTableService"/>
<property name="webservice.wsdl.url"
value="localhost:7001/TableCrud/CrudTableService"WSDL"/>
<property name="package.name" value="vs.crudClient.saaj" /> <!-- -->
<!-- Standard WebLogic ANT tasks -->
<taskdef name="jwsc" classname="ls.anttasks.JwscTask" />
<taskdef name="clientgen" classname="ls.anttasks.ClientGenTask" /> <taskdef name="wldeploy" classname="weblogic.ant.taskdefs.management.WLDeploy"/> <!--
========================================
Path Section
========================================
-->
<path id="javabuild.class.path">
<pathelement path="${classes.dir}"/>
<fileset dir="${weblogic.home}/server/lib">
<include name="weblogic.jar"/>
<include name="webserviceclient.jar"/>
<include name="*bean.jar"/>
</fileset>
</path>
<path id="jwsbuild.class.path">
<fileset dir="${weblogic.home}/server/lib">
<include name="weblogic.jar" />
<include name="*bean.jar" />
</fileset>
<fileset dir="${jdk5.home}/lib">
<include name="tools.jar" />
</fileset>
</path>
<path id="clientrun.class.path">
<pathelement path="${classes.dir}"/>
<pathelement path="${generated.src.dir}"/>
<fileset dir="${weblogic.home}/server/lib">
<include name="weblogic.jar"/>
<include name="webserviceclient.jar"/>
</fileset>
</path>
<target name="all" depends="clean,generate,build,run" description="Build and run the SAAJ client"/>
<target name="build"
description="==> Build the SAAJ Client Files.">
<!-- pile the generated Java source first -->
<echo>pile the generated client utility files.</echo>
<javac srcdir="${generated.src.dir}"
destdir="${classes.dir}"
includes="**/*.java"
debug="on"
classpathref="javabuild.class.path"/>
<!-- pile the client source file -->
<echo>pile the client source file.</echo>
<javac srcdir="${src.dir}"
destdir="${classes.dir}"
includes="**/*Client.java"
debug="on"
classpathref="javabuild.class.path"/>
<!-- END: Generate and pile Web Services client classes -->
</target>
<target name="generate"
description="Generates the AsyncRRClientService client. Be sure the web service is running before you e*ecute this task.">
<!-- BEGIN: Generate and pile Web Services client classes -->
<echo>Generating the client code</echo>
<clientgen wsdl="${webservice.wsdl.url}"
destDir="${generated.src.dir}"
packageName="${package.name}" />
</target>
<target name="clean" description="Removes all generated files">
<delete dir="${javadoc.dir}" failonerror="false"/>
<delete dir="${classes.dir}" failonerror="false"/>
<delete dir="${generated.src.dir}" failonerror="false"/>
<mkdir dir="${classes.dir}" />
<mkdir dir="${generated.src.dir}" />
</target>
<target name="run" description="Run the client test program">
<java fork="yes" classname="${package.name}.DasEsbServiceClient" failonerror="true"> <classpath refid="clientrun.class.path"/>
</java>
</target>
</project>
图中红局部需要根据具体情况进展修改
5.运行Ant的bulid.*ml生成客户端存根类
6.编写客户端Java类并进展测试
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论