axis1 创建service服务端 , axis1 客户端
发布时间:2020-12-17 00:17:33 所属栏目:安全 来源:网络整理
导读:? axis1 服务端配置 1、首先 建立一个项目 axisTest 不需多说 ? 2、在lib下放入需要的jar包 ?点击下载 :axis所需的jar包下载 3、 然后需要在web.xml里面加入: servlet ???? servlet-name AxisServlet / servlet-name ???? display-name Apache-Axis?Servle
?
axis1 服务端配置
1、首先建立一个项目 axisTest 不需多说 ? 2、在lib下放入需要的jar包 ?点击下载 :axis所需的jar包下载 3、然后需要在web.xml里面加入:
<servlet>
????<servlet-name>AxisServlet</servlet-name>
????display-name>Apache-Axis?Servletdisplay-name>
????servlet-class>
????????org.apache.axis.transport.http.AxisServlet
????servlet-class>
?servlet>
?servlet-mapping>
????url-pattern>/servlet/AxisServleturl-pattern>
?servlet-mapping>
?url-pattern>*.jwsurl-pattern>/services/*url-pattern>
?servlet-mapping>??
4、创建服务端的代码:
? ?package?com.service;
???public?class?myService?{
???????public?String?getusername(String?name){/**用spring的时候需要添加你要注入的bean
???????????baseTransaction?=?(BaseTransaction)?getApplicationContext().getBean("baseTransaction")**/
???????????return?"Hello?"+name+",this?is?an?Axis?Web?Service";?
???????????}
???}
??
5、在WEB-INF下创建service-config.wsdd 文件,内容如下:
<
deployment
?
xmlns="http://xml.apache.org/axis/wsdd/"??xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"
>
handler?type="java:org.apache.axis.handlers.http.URLMapper"?name="URLMapper"/>???
???service?name="myService"?provider="java:RPC">
???????<!--这里的name是你的service名字?访问的时候要用得着的-->
???????parameter?"className"?value="com.service.myService"/>
<!--这里的value是你所提供的的供外部访问的方法所在的类-->
????????"allowedMethods"?"getusername"
????????<!--供外部访问的方法-->
????service>
transport?"http">
?requestFlow>
type="URLMapper"</transport>
</deployment>
??
6、启动tomcat 访问地址:
http://localhost:8080/axisTest/servlet/AxisServlet
axis1 客户端调用
package?com.axistest;
import?java.net.MalformedURLException;
import?java.rmi.RemoteException;
import?javax.xml.rpc.ServiceException;
import?org.apache.axis.client.Call;
import?org.apache.axis.client.Service;
public?class?myServiceTestorByWSDD?{
????static?void?main(String[]?args)?throws?ServiceException,MalformedURLException,?RemoteException?{
????/**假如访问的时候有spring注入的情况?则需要?添加
????baseTransaction?=?(BaseTransaction)?getApplicationContext().getBean("baseTransaction");?来获取spring的注入信息。实在service层添加的。**/
????String?endpoint?=?"http://localhost:8080/axisTest/services/myService";
????Service?service?=?new?Service();?//?创建一个Service实例,注意是必须的!
????Call?call?=?(Call)?service.createCall();?//?创建Call实例,也是必须的!
????call.setTargetEndpointAddress(new?java.net.URL(endpoint));//?为Call设置服务的位置
????call.setOperationName("getusername");?//?注意方法名与JavaBeanWS.java中一样!!
????String?res?=?(String)?call.invoke(new?Object[]?{?"邹萍"?});?//?返回String,传入参数
????System.out.println(res);
? ??
????}
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |