构建Webservices服务 axis引擎

AXIS 必要的jar包,放入web项目的lib目录

axis-ant.jar
axis.jar
commons-discovery-0.2.jar
commons-logging-1.0.4.jar
jaxrpc.jar
log4j-1.2.8.jar
saaj.jar
wsdl4j-1.5.1.jar

 

在web.xml 加入以下信息

<servlet>
		<servlet-name>AxisServlet</servlet-name>
		<servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
	</servlet>

	<servlet-mapping>
		<servlet-name>AxisServlet</servlet-name>
		<url-pattern>*.jws</url-pattern>
	</servlet-mapping>

	<mime-mapping>
		<extension>wsdl</extension>
		<mime-type>text/xml</mime-type>
	</mime-mapping>

	<mime-mapping>
		<extension>xsd</extension>
		<mime-type>text/xml</mime-type>
	</mime-mapping>

 

编写MyMath.java 文件 实现方法,(注意这个类不要放入任何包下)。写完后在webRoot目录下新建axis文件夹,把这个文件改成MyMath.jws 后缀。就大功告成啦

构建Webservices服务 axis引擎_第1张图片

 

http://localhost:8080/MyAppServer/axis/MyMath.jws?wsdl

这个路径就是webservice路径

构建Webservices服务 axis引擎_第2张图片

 

接下来就是靠客户端解析了,接口已经完成了

客户端同样导入lib jar包

private static void getWebserver()
	{
		Service service =new Service();
		try
		{
			Call call = (Call) service.createCall();
			call.setTargetEndpointAddress(new URL("http://localhost:8080/MyAppServer/axis/MyMath.jws?wsdl"));
			Integer result = (Integer) call.invoke("squared", new Object[]{30});  //传入参数
			System.out.println(result);
			
		} catch (ServiceException e)
		{
			e.printStackTrace();
		} catch (MalformedURLException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (AxisFault e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

 

你可能感兴趣的:(构建Webservices服务 axis引擎)