1. 程式人生 > >CXF WebService 學習總結

CXF WebService 學習總結

一、需要的引入的jar包(具體存在了百度雲裡面)

二、web.xml配置

1、引入cxf-servlet.xml檔案

具體寫法如下:

<web-app>

<context-param>

      <param-name>contextConfigLocation</param-name>

     <param-value>

     /WEB-INFO/cxf-servlet.xml

     </param-value>

</context-param>

</web-app>

三、編寫介面和java類

1、介面:

import java.util.Map;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.bind.annotation.XmlSeeAlso;
import com.inspur.sdm.mapplus.ObjectFactory;

@WebService(targetNamespace = "http://som.inspur.com", name = "BCSFlowService")
@XmlSeeAlso({ObjectFactory.class})
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface IBCSFlowService {
    /**
     * im介面
     * @param flowId
     * @param xml
     * @return
     */
    @WebMethod(operationName = "replyIM")
    @WebResult(name = "replyIM_response", partName = "request")
    public String replyIM(@WebParam(name = "flowId") String flowId,@WebParam(name = "xml") String xml);
    
    
    @WebMethod(operationName = "replyAM")
    @WebResult(name = "replyAM_response", partName = "request")
    public String replyAM(@WebParam(name = "xml") String xml);
    
    
    @WebMethod(operationName = "replyWFM")
    @WebResult(name = "replyWFM_response", partName = "request")
    public String replyWFM(@WebParam(name = "sevType") String sevType,@WebParam(name = "xml") String xml);
    
    

}

2、java類:

@javax.jws.WebService(
        serviceName = "BCSFlowService",
        portName = "BCSFlowService_servicePort",
        targetNamespace = "http://som.inspur.com",
        wsdlLocation = "file:/F:/BCSFlowService.wsdl",
        endpointInterface = "com.inspur.om.webService.wsInterfaces.IBCSFlowService")
@Service("BCSFlowService")
public class BCSFlowService implements IBCSFlowService{

    private static Logger log = Logger.getLogger(BCSFlowService.class);
    @Autowired
    private JdbcTemplate jdbcTemplate;
    
    @Autowired
    private RedisTemplate<Serializable, Serializable> redisTemplate;
    @Autowired
    private IProcessDefService processDefService;
    public String replyIM(@WebParam(name = "flowId") String flowId,
            @WebParam(name = "xml") String xml) {
        
    }
 

四、cxf-servlet.xml配置

<?xml version="1.0" encoding="UTF-8"?>  
  
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns:jaxws="http://cxf.apache.org/jaxws"  
    xsi:schemaLocation="  
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">  
          
  <import resource="classpath:META-INF/cxf/cxf.xml" />

 <!-- OM Web Service -->
  <jaxws:server id="BCSFlowService" serviceClass="com.inspur.om.webService.wsInterfaces.IBCSFlowService" address="/BCSFlowService">  
    <jaxws:serviceBean>
        <bean class="com.inspur.om.webService.service.BCSFlowService" />  
    </jaxws:serviceBean>
  </jaxws:server>

  
</beans>