webservice发布示例

来源:互联网 发布:兄弟连php培训费用 编辑:程序博客网 时间:2024/05/17 23:17

步骤:1、新建项目,命名:serviceTest,在src下新建一个文件夹。命名为META-INF 然后再META-INF下新建一个xfire文件夹,接着在xfire下新建一个services.xml文件(必须这样命名)

 

2、在myeclipse中加如相应的xfire jar包

 

3、新建一个接口,及其实现类

(1)接口
public interface SoapDao {
public String getSoap();
}
(2)实现类
public class SoapDaoImpl implements SoapDao {

 public String getSoap() {
  // TODO Auto-generated method stub
  return "success";
 }

}

 

4、在web.xml中配置xfire

<servlet> 
        <servlet-name>xfire</servlet-name> 
        <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class> 
    </servlet> 
 
    <servlet-mapping> 
        <servlet-name>xfire</servlet-name> 
        <url-pattern>/services/*</url-pattern> 
    </servlet-mapping>

 

 

5、在刚刚建好的services.xml如下配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
  <name>getSoap</name><!-- 发布的接口名称 -->
  <serviceClass>SoapDao</serviceClass><!-- 接口名称 -->
  <implementationClass>SoapDaoImpl</implementationClass><!-- 接口的实现类 -->
</service>
</beans>

 

6、用tomcat发布项目

 

7、http://localhost:8080/WebserviceTest/services 访问这个地址,就可以看到你发布的接口。点击接口,可以看到一个xml页面,地址为http://localhost:8080/WebserviceTest/services/soapDao?wsdl 。发布成功!s