webService Xfire与sping整合

首先:发布webService接口流程:

    1.导入jar包

     XmlSchema-1.1.jar,xfire-all-1.2.6.jar,wsdl4j-1.6.1.jar,org.springframework.web-3.1.1.RELEASE.jar,org.springframework.web.servlet-3.1.1.RELEASE.jar,org.springframework.expression-3.1.1.RELEASE.jar,org.springframework.core-3.1.1.RELEASE.jar,org.springframework.context-3.1.1.RELEASE.jar,org.springframework.beans-3.1.1.RELEASE.jar,org.springframework.asm-3.1.1.RELEASE.jar,org.springframework.aop-3.1.1.RELEASE.jar,jdom-1.0.jar,commons-logging-1.1.1.jar,commons-httpclient-3.0.jar,commons-codec-1.3.jar   加红吧,期间最头疼的就是这些jar文件,要不就是找的是错的,就不就是不全,要不就是xfire与spring的版本冲突,获取需要条件下载!!!伤心总是如此。另外注意这个xfire的jar包已经全部导入了,不需要再导入其他的xfire的jar包

    2.创建提供服务的接口

package com.ljj.service;

public interface BookService {
  public String getBook(String xml);
}

    3.创建提供服务接口的实现类

package com.ljj.serviceimpl;

import com.ljj.service.BookService;

public class BookServiceImpl implements BookService {

  public String getBook(String xml) {
    return xml;
  }

}

 

    4.配置web.xml文件




 Archetype Created Web Application
 
         org.springframework.web.context.ContextLoaderListener
   
   
       contextConfigLocation
       classpath:spring/*.xml
   
   
      
     xfire  
       
      org.codehaus.xfire.spring.XFireSpringServlet  
       
      
      
     xfire  
     /service/*  
      

 

    5.配置spring的配置文件:




    
        
     
          
      
           
       
          
         
      
       
         
          
      
           
        
          
       

6.测试

启动服务后在浏览器访问:http://localhost:8080/xfireServer/service/BookService?wsdl看到如下页面即为成功





















 


 



 
 




















扩展:xfire自定义参数名

        1.在接口类里边加入注解

@WebService
public interface testService{
@WebMethod  
@WebResult(name="resultMsg")  
public String getExpertUserId(@WebParam(name="name")String name,@WebParam(name="sex")String sex);
}

2.在接口类相同的文件夹下边创建testService.aegis.xml文件

  
     
         
            
              
               
                   
        

本地编写main方法,测试逻辑代码

public static void main(String[] args) {
		org.codehaus.xfire.service.Service srvcModel = new ObjectServiceFactory()
		.create(ExpertLoginService.class);
		XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
		.newInstance().getXFire());
		String helloWorldURL = "http://192.168.XX.XX:8080/项目名称/service/ExpertLoginService";
		try {
			ExpertLoginService srvc = (ExpertLoginService) factory.create(
		srvcModel, helloWorldURL);
		System.out.print(srvc.getExpertUserId("username", "password"));
		} catch (MalformedURLException e) {
		e.printStackTrace();
		}
		}

你可能感兴趣的:(xfire,Xfire,webservice,xfire自定义参数名)