WebService(二)发送数据+接收数据并进行处理操作

(一)使用WebService发送数据

1.定义webService接口
import java.util.List;
import javax.jws.WebParam;
import javax.jws.WebService;
import com.mxz.fvp.dto.ADto;
 
@WebService
public interface MxzReceiveService {
    public boolean addExpressBarRecord(@WebParam(name = "record") ADto record) throws Exception;// 方法1
    public boolean batchAddExpressBarRecord(@WebParam(name = "listRecord") List listRecord) throws Exception; // 方法2
}

2.工具类的创建

public class AUtil {
    private final static Logger logger = Logger.getLogger(AUtil.class);
    private static ApplicationContext factory = null;
    private static MxzReceiveService mxzReceiveService ;
    private static BService bService;
    static {
        factory = new ClassPathXmlApplicationContext("classpath:application-*.xml");
        bService = (BService) factory.getBean("bService");
    }
 
    private static synchronized MxzReceiveService getMxzReceiveService () {
      try {
            if (mxzReceiveService  == null) {
              JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
              factory.setServiceClass(MxzReceiveService class); // 1设置请求接口
              String linkUrl = CommonDataUtil.getConfigValue(ServiceConstants.MXZ_WEBSERVICE_URL);// 2查询数据库获取链接地址
              factory.setAddress(linkUrl + "services/MxzReceiveService "); //3设置地址
              mxzReceiveService = (MxzReceiveService ) factory.create(); // 4创建客户端对象
           }
      } catch (Exception e) {
          logger.error("mxzReceiveService Webservice initial error!");
          mxzReceiveService = null;
     }
      return mxzReceiveService ;
   }

3.具体使用

    public static void batchAddExpressBarRecord(List listRecord) {
        try {
                if(getFvpReceiveService() == null) // 3.1初始化链接对象
                       return;           
 
            //3.2数据其他处理操作
            if(!validateCode(listRecord))
                 return;   
       
           // 3.3调用接口
            boolean isSendSuccess = mxzReceiveService .batchAddExpressBarRecord(listRecord);
            if(!isSendSuccess) {
                //....其他操作
                return;
            }
            triggerCsdOorderBackState(listRecord); //3.3其他操作
        } catch (Exception e) {    //3.3其他操作
            saveSendFvp(listRecord, "m"); //....其他操作
            logger.error("Sent to mxzReceiveService.batchAddExpressBarRecord fail!" + e.getMessage());
        }
   }

 

(一)使用WebService接收数据并处理
1.创建webService接口
xml配置	


	
	
	
	
	
	

	
	
		
	

  

import javax.jws.WebParam;
import javax.jws.WebService;
 
@WebService(targetNamespace = "http://rece/")
public interface AServer {
public void receiveLog(@WebParam(name = "wayNo") String wayNo,
        @WebParam(name = "inputTypeCode") String inputTypeCode,
        @WebParam(name = "isSuccess") boolean isSuccess,
        @WebParam(name = "failreason") String failreason);   
}

2.定义接口实现类,并实现其他操作

@WebService(targetNamespace = "http://waybilllog/", endpointInterface = "com.mxz.service.webService.AServer ")
public class AServerImpl implements AServer{
      private Logger logger=Logger.getLogger(this.getClass()); // this:AServerImpl 
      private BService bService; //提供gettter/setter方法
      private CDaoImpl cDao; //提供gettter/setter方法
 
@Override
public void receiveLog(String waybillNo, String inputTypeCode, boolean isSuccess, String failreason) {
            logger.info("接收返回结果:单号"+wayNo+",类型:"+inputTypeCode+",状态:"+isSuccess+",描述:"+failreason);
           
            try{ //其他操作
                 .........................
           }catch(Exception ex){
                logger.error("接收返回结果失败:"+wayNo+","+inputTypeCode+","+isSuccess+","+failreason,ex);
          }
   }
}

 

 
 
 

转载于:https://www.cnblogs.com/mxzer/p/6411632.html

你可能感兴趣的:(WebService(二)发送数据+接收数据并进行处理操作)