maven项目,ssm框架
服务端
1、pom.xml配置,axis-1.4.jar放一份到tomcat目录lib下
<!-- axis 1.4 jar start -->
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.2</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-jaxrpc</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-saaj</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-remoting</artifactId>
<version>2.0.8</version>
</dependency>
<!-- axis 1.4 jar end -->
2、创建一个接口
public interface IWebServiceTest {
public String getDate(String date);
}
3、创建接口的实现类
public class WebServiceTest extends ServletEndpointSupport implements IWebServiceTest {
private LoginService loginService;
@Override
protected void onInit() throws ServiceException {
System.out.println("我是初始化!");
loginService = (LoginService) getApplicationContext().getBean("loginService");
}
@Override
public String getDate(String date) {
System.out.println(loginService);
return date+"----成功!";
}
}
4、配置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>/services/*</url-pattern>
</servlet-mapping>
5、添加webservice用的配置文件server-config.wsdd
这个文件放到web.xml的同级目录下也就是WEB-INF下
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper" />
<service name="Test" provider="java:RPC">
<parameter name="className" value="com.base.webservice.WebServiceTest" />
<parameter name="allowedMethods" value="*" />
</service>
<transport name="http">
<requestFlow>
<handler type="URLMapper" />
</requestFlow>
</transport>
</deployment>
6、启动项目访问
http://localhost:8080/xxxxx/services/Test?wsdl
出现这个页面发布成功
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://192.168.100.176:8080/fycnxq/services/Test" xmlns:intf="http://192.168.100.176:8080/fycnxq/services/Test" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://192.168.100.176:8080/fycnxq/services/Test">
<!--
WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)
-->
<message name="getDateResponse">
<part name="getDateReturn" type="soapenc:string"/>
</message>
<message name="getDateRequest">
<part name="date" type="soapenc:string"/>
</message>
<portType name="WebServiceTest">
<operation name="getDate" parameterOrder="date">
<input message="impl:getDateRequest" name="getDateRequest"/>
<output message="impl:getDateResponse" name="getDateResponse"/>
</operation>
</portType>
<binding name="TestSoapBinding" type="impl:WebServiceTest">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getDate">
<wsdlsoap:operation soapAction=""/>
<input name="getDateRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservice.base.com" use="encoded"/>
</input>
<output name="getDateResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://192.168.100.176:8080/fycnxq/services/Test" use="encoded"/>
</output>
</operation>
</binding>
<service name="WebServiceTestService">
<port binding="impl:TestSoapBinding" name="Test">
<wsdlsoap:address location="http://192.168.100.176:8080/fycnxq/services/Test"/>
</port>
</service>
</definitions>
客户端
1、下载如下jar包,放到同一个文件夹中
2、在此文件夹中打开cmd,运行命令
java -cp activation-1.1.jar;axis-1.4.jar;commons-discovery-0.2.jar;commons-logging-1.1.jar;jaxrpc-api-1.1.jar;mail-1.4.jar;saaj-api-1.3.jar;wsdl4j-1.4.jar org.apache.axis.wsdl.WSDL2Java http://localhost:8080/xxxxx/services/Test?wsdl
生成这四个文件
3、创建web项目作为客户端
导入上面的jar和java文件
创建ServiceTest.clss
public static void main(String[] args) throws ServiceException, RemoteException {
WebServiceTestService locator=new WebServiceTestServiceLocator();
TestSoapBindingStub stub=(TestSoapBindingStub)locator.getTest();
String result=stub.getDate("2017111111");
System.out.println("result:"+result);
}
4、输出结果:
服务端:
我是初始化!
com.base.service.impl.LoginServcieImpl@7ebffc91
客户端:
result:2017111111----成功!