【转载】了解Weblogic9下面的Web Service_Tomcat, WebLogic及J2EE讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  Tomcat, WebLogic及J2EE讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 3399 | 回复: 0   主题: 【转载】了解Weblogic9下面的Web Service        下一篇 
众里寻他
注册用户
等级:少尉
经验:383
发帖:27
精华:1
注册:2013-2-25
状态:离线
发送短消息息给众里寻他 加好友    发送短消息息给众里寻他 发消息
发表于: IP:您无权察看 2013-2-28 10:57:24 | [全部帖] [楼主帖] 楼主

一:生成Web Service实现类
Web Service类与java普通类没有太大区别,只 是在类前面加上各项annotation然后编译发布即成为Web Service。
annotation是JDK1.5版本提供 的新功能。 WebLogic9使用了此功能。
示范程序:

package com.mycompany.webservices.moto;
// Import the standard JWS annotation interfaces
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
// Import the WebLogic-specific JWS annotation interface
import weblogic.jws.WLHttpTransport;
// Standard JWS annotation that specifies that the portType name of the Web
// Service is "BOLServicePortType", its public service name is "BOLService",
// and the targetNamespace used in the generated WSDL is " http://127.0.0.1"
@WebService(serviceName="BOLService", name="BOLServicePortType", targetNamespace="http://127.0.0.1")
// Standard JWS annotation that specifies this is a document-literal-wrapped
// Web Service
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT, use=SOAPBinding.Use.LITERAL, parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)
// WebLogic-specific JWS annotation that specifies the context path and service
// URI used to build the URI of the Web Service is "MOTOWebService/BOLService"
@WLHttpTransport(contextPath="MOTOWebService", serviceUri="BOLService", portName="BOLServicePort")
public class BOLServiceImpl {
      public String testAction(String s) {
            System.out.println("The testAction in BOL webservice has "+
            "been invoked with arguments: " + s );
            String returnValue = "The testAction in BOL webservice has "+
            "been invoked with arguments: " + s ;
            return returnValue;
      }
}


说明:
上面的黑体字是JAVA普通类的基础上增加上去的。没有这些annotation,这就是一普通的JAVA类。

类中默认所有public方法是对外公布的,如果想控制public方法是否对外公布,可以使用@WebMethod annotation来进行控制。
对Web Service类进行编译,发布
整体目录结构为:
MOTOWebService 工作目录
output 编译输出目录
src 源代码
build. xml ant编译 文件
setEnv.cmd 内容为:

call X:\bea91\weblogic91\samples\domains\wl_ server\setExamplesEnv.cmd


build.xml文件内容参考:

<project name="webservices-moto" default="all">
<!-- set global properties for this build -->
<property name="wls.username" value="weblogic" />
<property name="wls.password" value="manager001" />
<property name="wls.hostname" value="127.0.0.1" />
<property name="wls.port" value="7001" />
<property name="wls.server.name" value=" AdminServer" />
<property name="ear.deployed.name" value="MOTOWebService" />
<property name="motowebservice-output" value="output" />
<property name="ear-dir" value="${motowebservice-output}/MOTOWebService" />
<property name="ear-name" value="MOTOWebService.ear" />
<taskdef name="jwsc" classname="weblogic.wsee.tools.anttasks.JwscTask" />
<taskdef name="wldeploy" classname="weblogic.ant.taskdefs.management.WLDeploy"/>
<target name="all" depends="clean,build-service,deploy" />
<target name="clean" depends="undeploy">
<delete dir="${motowebservice-output}"/>
</target>
<target name="build-service">
<jwsc srcdir="src" destdir="${ear-dir}" keepGenerated="true">
<jws file="com/mycompany/webservice/moto/BOLServiceImpl.java" />
</jwsc>
<jar jarfile="${motowebservice-output}/${ear-name}" basedir="${ear-dir}" />
</target>
<target name="deploy">
<wldeploy action="deploy" name="${ear.deployed.name}"source="${ear-dir}" user="${wls.username}" password="${wls.password}"verbose="true" adminurl="t3://${wls.hostname}: ${wls.port}"targets="${wls.server.name}" />
</target>
<target name="undeploy">
<wldeploy action="undeploy" name="${ear.deployed.name}"failon error="false" user="${wls.username}" password="${wls.password}"verbose="true" adminurl="t3://${wls.hostname}: ${wls.port}"targets="${wls.server.name}" />
</target>
</project>


注意内容中的黑体字,为编译Web Service源代码的内容。

先执行setEnv.cmd以 设置环境,然后可以输入ant build-service仅编译文件,如果直接输入ant将 自动undeploy,然后编译,然后再deploy,发布 应用到WebLogic域中。
在控制台中查看WSDL
打开WebLogic的console,在左边树中选择“Deployments”;然后在右边的页面单击“MOTOWebService”超链接;在出现的页面中再单击最下方的“BOLService”。
在新页面中,选择标签“Testing”,如果出现的BOLService的Comments为“This Web Service isnot currentlyavailable”,则需要重新启动WebLogic,正常情况,可以扩展此处的BOLService 节点,然后可以查看它的WSDL等内容。
二:生成测试客户端
示范程序如下:

package client;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
public class Client {
      public static void main(String[] args) throws Exception{
            String wsdl = args[0];
            BOLService service = new BOLService_Impl(wsdl);
            BOLServicePortType port = service.getBOLServicePort();
            String result = port.testAction("Hi there!");
            System.out.println("the result is:" + result);
      }
}


黑体字为生成 服务接口。如果有不明白的,可以参考ant编译输出目录output\clientclass 目录下面的java文件与class进行比照。
对客户端程序进行编译,运行
目录结构为:
MotoWebServiceClient 工作目录
output 编译输出
src 源代码
build.xml ant编译文件
setEnv.cmd 内容为:

call X:\bea91\weblogic91\samples\domains\wl_server\setExamplesEnv.cmd


build.xml文件内容参考:

<project name="webservices-client" default="all">
<!-- set global properties for this build -->
<property name="wls.hostname" value="127.0.0.1" />
<property name="wls.port" value="7001" />
<property name="motowebservice-client-output" value="output" />
<property name="clientclass-dir" value="${motowebservice-client-output}/clientclass" />
<path id="client.class.path">
<pathelement path="${clientclass-dir}"/>
<pathelement path="${java.class.path}"/>
</path>
<taskdef name="clientgen" classname="weblogic.wsee.tools.anttasks.ClientGenTask" />
<target name="all" depends="clean,client,run"/>
<target name="clean">
<delete dir="${motowebservice-client-output}"/>
</target>
<target name="client">


<clientgen wsdl="http://${wls.hostname}北京联动北方科技有限公司{wls.port}/MOTOWebService/BOLService?WSDL" destDir="${clientclass-dir}" packageName="client"/>

<javac srcdir="${clientclass-dir}" destdir="${clientclass-dir}" includes="client/**/*.java"/>
<javac srcdir="src" destdir="${clientclass-dir}" includes="client/**/*.java"/>
</target>
<target name="run">
<java fork="true" classname="client.Client" failonerror="true" >
<classpath refid="client.class.path"/>
<arg line=" HTTP://${wls.hostname}{wls.port}/MOTOWebService/BOLService?WSDL" />
</java>
</target>
</project>


黑体字为通过WSDL生成java源文件与class的内容。用到了clientgen,具体可以参考bea公司提供的 资料。
先执行setEnv.cmd以设置环境,然后可以输入ant client仅编译文件;如果直接输入ant将自动编译,然后运行;输入ant run则只是运行程序。
到此,WebLogic9中的Web Service基本 开发工作结束。

参考文档:

Web Services for BEA WebLogic Server? 9.1
http://e-docs.bea.com/wls/docs91/webservices.html




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论