加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

创建与调用以axis实现的stub方式webservice服务

发布时间:2020-12-17 00:35:25 所属栏目:安全 来源:网络整理
导读:1.下载apache公司的axis包.将lib拷贝到工程中 2.将axis包中的web.xml相关配置拷贝到自己的web.xml中 3.在WEB-INF下建立server-config.wsdd 如: ??? xmlns:handler="http://xml.apache.org/axis/wsdd/providers/handler" ??? xmlns="http://xml.apache.org/ax



1.下载apache公司的axis包.将lib拷贝到工程中
2.将axis包中的web.xml相关配置拷贝到自己的web.xml中
3.在WEB-INF下建立server-config.wsdd
如:


??? xmlns:handler="http://xml.apache.org/axis/wsdd/providers/handler"
??? xmlns="http://xml.apache.org/axis/wsdd/"
??? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
??? name="defaultClientConfig" xsi:type="deployment">
???
???????
???????
???????
??????????? ??????????????? type="java:org.apache.axis.handlers.JWSHandler" regenerateElement="false">
???????????????
???????????
??????????? ??????????????? type="java:org.apache.axis.handlers.JWSHandler" regenerateElement="false">
???????????????
???????????????
???????????
???????
???
??? ??????? type="java:org.apache.axis.handlers.http.URLMapper" regenerateElement="false"/>
??? ??????? type="java:org.apache.axis.transport.local.LocalResponder" regenerateElement="false"/>
??? ??????? type="java:org.apache.axis.handlers.SimpleAuthenticationHandler" regenerateElement="false"/>
???
??????? ??????????? value="org.apache.axis.transport.http.QSListHandler" regenerateElement="false"/>
??????? ??????????? value="org.apache.axis.transport.http.QSMethodHandler" regenerateElement="false"/>
??????? ??????????? value="org.apache.axis.transport.http.QSWSDLHandler" regenerateElement="false"/>
???????
???????????
??????????? ??????????????? type="java:org.apache.axis.handlers.http.HTTPAuthHandler" regenerateElement="false"/>
???????
???
???
???????
???????????
???????
???
???
???
????? ??????? provider="java:RPC" style="rpc" use="encoded" validate="true">
???????
??????? ??????????? value="com.xkk.webservice.service.example.impl.SayHello" regenerateElement="false"/>
???????
??????? http://impl.example.service.webservice.xkk.com
???
???
????


保存wsdd
然后部署到服务器中.


4.打开以下网址
http://localhost:8080/你的工程名/servlet/AxisServlet
从以下网址中获得? SayHello.wsdl文件
http://localhost:8080/testSimpleAxisService/services/SayHello?wsdl


5.新建客户端工程
将SayHello.wsdl放到工程根目录下.
执行控制台命令.生成客户端调用web程序
如:
set Axis_Lib=H:/place/WebRoot/WEB-INF/lib
set Java_Cmd=java -Djava.ext.dirs=%Axis_Lib%
set Output_Path=H:/place/testAxisCustomer/src
set Package=com.test
%Java_Cmd% org.apache.axis.wsdl.WSDL2Java -o%Output_Path% -p%Package% server-config.wsdl pause
也可以用eclispe配置参数执行控制台程序
将其放入指定包下

6.执行web客户端调用程序 import java.rmi.RemoteException; import javax.xml.rpc.ServiceException; import com.xxx.webservice.guest.sayHello.SayHelloServiceLocator; import com.xxx.webservice.guest.sayHello.SayHelloSoapBindingStub; public class TestMain { ??? private static SayHelloSoapBindingStub binding; ??? static { ??????? SayHelloServiceLocator bssl=new SayHelloServiceLocator(); ??????? //web服务的服务端的地址 ??????? bssl.setSayHelloEndpointAddress("http://localhost:8080/你的web工程服务端/services/SayHello");??????? ??????? try { ??????????? binding = (SayHelloSoapBindingStub)bssl.getSayHello(); ??????? } catch (ServiceException e) { ??????????? // TODO Auto-generated catch block ??????????? e.printStackTrace(); ??????? } ??????? binding.setTimeout(6000); ??? } ??? public String sayHello() throws RemoteException { ????? return binding.toSayHello("小王21212"); ??? } ??? public static void main(String[] args) { ??????? TestMain testMain = new TestMain(); ??????? try { ??????????? System.out.println(testMain.sayHello()); ??????? } catch (RemoteException e) { ??????????? // TODO Auto-generated catch block ??????????? e.printStackTrace(); ??????? } ??? } }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读