标签:@param mic blog mamicode www date map sim string
今天在对接的时候客户用到了webservice,用wsimport生成本地代理的方式可以访问ws服务,但是想的完整的总结一下ws的几种调用方式。
发布服务的IP地址是:192.168.15.195
客户端访问ws服务的IP是:
参考:https://www.cnblogs.com/qlqwjy/p/9644078.html
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" 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/jaxws http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <jaxws:endpoint id="userServiceWS" implementor="cn.xm.exam.service.impl.webservice.UserWebServiceImpl" address="/userServiceWS"> </jaxws:endpoint> </beans>
web.xml如下:
<servlet> <servlet-name>CXFServlet</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/WS/*</url-pattern> </servlet-mapping>
package cn.xm.exam.service.webservice; import java.util.Set; import javax.jws.WebService; import cn.xm.exam.bean.system.User; @WebService public interface UserWebService { /** * 根据用户身份证号码查询用户信息及其角色信息及其权限信息 * * @param useridcard * @return user */ public User getUserByUseridcard(String useridcard) throws Exception; /** * 根据用户编号查询角色code的集合 * * @param userid * @return 角色集合 */ public Set<String> getRoleByUserid(String userid) throws Exception; }
package cn.xm.exam.service.impl.webservice; import java.util.Set; import javax.annotation.Resource; import javax.jws.WebService; import org.springframework.stereotype.Service; import cn.xm.exam.bean.system.User; import cn.xm.exam.mapper.system.UserMapper; import cn.xm.exam.service.webservice.UserWebService; import cn.xm.exam.utils.ValidateCheck; @Service @WebService(targetNamespace = "http://webservice.service.exam.xm.cn") public class UserWebServiceImpl implements UserWebService { @Resource private UserMapper userMapper; @Override public User getUserByUseridcard(String useridcard) { if (ValidateCheck.isNull(useridcard)) { return null; } User user = null; try { user = userMapper.getUserByUseridcard(useridcard); } catch (Exception e) { e.printStackTrace(); } return user; } @Override public Set<String> getRoleByUserid(String userid) { if (ValidateCheck.isNull(userid)) { return null; } Set<String> role = null; try { role = userMapper.getRoleByUserid(userid); } catch (Exception e) { e.printStackTrace(); } return role; } }
启动之后查看ws服务:
查看wsdl:
标签:@param mic blog mamicode www date map sim string
原文地址:https://www.cnblogs.com/qlqwjy/p/10567378.html