.net调用java webservice基于JBOSS服务器 学习笔记(一)

1、遇到数组类型或List等复杂数据类型是,需要对其进行包装,就是将复杂数据类型放到一个类里面:

public class VOCargoJTWS {
    /** JT列表  */
    private List<TBLCargoJT> cargoJTs;    
    /** 分页数据信息*/
    private PageInfo pageInfo;
    
    
    public VOCargoJTWS() {
        super();
    }

    @SuppressWarnings("unchecked")
    public VOCargoJTWS(PageInfo pageInfo) {
        super();
        this.cargoJTs = (List<TBLCargoJT>) pageInfo.getList();
        this.pageInfo = pageInfo;
        pageInfo.setList(null);
    }}

 2.基于JBOSS服务器发布webservice:

  在浏览器可以看到发布信息,访问地址http://lenovo-pc/EvisaWS/CargoJTService?wsdl 。

@Stateless
@WebService
@WebContext(contextRoot = "/EvisaWS", urlPattern = "/CargoJTService")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class CargoJTWSBean implements CargoJTWS {

    private static final Logger logger = Logger.getLogger(CargoJTWSBean.class);
    @EJB
    private CargoJTServiceLocal cargoJTServiceLocal;


    @WebMethod
    @WebResult(partName = "return")
    public VOCargoJTWS findPageInfo(Integer currentPage, Integer pageCount)  {
        try {
            PageInfo pageInfo = cargoJTServiceLocal.findPageInfo1(currentPage, pageCount);            
            VOCargoJTWS cargoJTWS = new VOCargoJTWS(pageInfo);
            return cargoJTWS;
        } catch (Exception e) {
            logger.error(e);
        }
        return null;
    }
}

 3、处理关联关系:

  如果类与类直接存在关联关系,不需要查询出子表信息时,可以直接将其设置为null。如果需要,那么可通过集合的size方法加载,子类的关联关系和父类关联关系的处理方式一样。

  如果出现循环调用,Parent--->Child--->Parent,可以在get属性上加 @XmlTransient 注释。

@Stateless
@Local(CargoJTServiceLocal.class)
@LocalBinding(jndiBinding = "CargoJTServiceBean/local")
@Remote(CargoJTServiceRemote.class)
@RemoteBinding(jndiBinding = "CargoJTServiceBean/remote")
public class CargoJTServiceBean implements CargoJTServiceLocal, CargoJTServiceRemote {

    private static final Logger logger = Logger.getLogger(CargoJTServiceBean.class);
    @EJB
    private CargoJTDaoLocal cargoJTDao;


    @SuppressWarnings("unchecked")
    public PageInfo findPageInfo1(Integer currentPage, Integer pageCount ) throws ServiceException {
        try {
            PageInfo piInfo = cargoJTDao.findPageInfo(currentPage, pageCount);
            List<TBLCargoJT> list = (List<TBLCargoJT>) piInfo.getList();
            for(TBLCargoJT cargoJT : list){
                cargoJT.getAssessType().getCode();
                cargoJT.setGoods(null);
            } 
            return piInfo;
        } catch (DAOException e) {
            logger.error(e);
            throw new ServiceException("", e);
        }
    }
}

 4、这是.net根据wsdl生成的类列表:

  要生成   voCargoJTWS   这个对象也就是在c#中可以看到,那么这个对象里面必须有两个以上的属性,否则这个对象不会生成。

原文地址:https://www.cnblogs.com/lbangel/p/3196084.html