WebService服务端与客户端XML配置⽂件
webservice
常⽤的数据格式:
json({}[])  xml(特点标签<></>)
采⽤的传输协议:
soap 它是⽤于交换(传输)XML(数据格式/结构)编码信息的轻量级协议
WSDL:
Web Service描述语⾔,⽤于描述Web Service及其函数、参数和返回值
如何生成webservice客户端A    调⽤ B
客户端服务端
常见的webservice 技术
cxf(xfire)  ⽀持语⾔少
axis2(axis) ⽀持语⾔多
使⽤ cxf 暴露⼀个接⼝
1.⾸先到jar包
<dependency>
<groupId>f</groupId>
<artifactId>cxf-rt-ws-security</artifactId>
<version>2.7.8</version>
</dependency>
<dependency>
<groupId>f</groupId>
<artifactId>cxf-api</artifactId>
<version>2.7.8</version>
</dependency>
<dependency>
<groupId>f</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.7.8</version>
</dependency>
<dependency>
<groupId>f</groupId>
<artifactId>cxf-rt-bindings-soap</artifactId>
<version>2.7.8</version>
</dependency>
<dependency>
<groupId>f</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.7.8</version>
</dependency>
2.在resource⽬录下创建⼀个l
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="/schema/beans"
xmlns:xsi="/2001/XMLSchema-instance"
xmlns:p="/schema/p"
xmlns:context="/schema/context"
xmlns:tx="/schema/tx"
xmlns:mvc="/schema/mvc"
xmlns:aop="/schema/aop"
xmlns:jaxws="/jaxws"
xsi:schemaLocation="
/schema/beans
/schema/beans/spring-beans.xsd
/schema/context
/schema/context/spring-context.xsd
/schema/aop
/schema/aop/spring-aop.xsd
/schema/mvc
/schema/mvc/spring-mvc.xsd
/jaxws
/schemas/jaxws.xsd">
<!-- 导⼊cxf配置⽂件 -->
<!-- 导⼊cxf配置⽂件 -->
<import resource="classpath:META-INF/l" />
<import resource="classpath:META-INF/l" />
<import resource="classpath:META-INF/l" />
<!-- 发布接⼝ -->
<jaxws:endpoint
id="cxfUserServiceWeb"
implementor="com.jk.cqd.service.impl.CxfUserServiceImpl"
address="/cxfUserService">
</jaxws:endpoint>
3.在接⼝的实现类上加上 @WebService注解
4:在l中加上如下配置
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>f.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/webservice/*</url-pattern>
</servlet-mapping>
5:在浏览器访问
ip地址:端⼝号/项⽬名/servlet url-pattern/spring-cxf中的address?wsdl
客户端如何调⽤webservice的服务端接⼝
1:⾃动⽣成客户端代码
命令
-
p 包结构
-client 值得是服务端的接⼝地址
wsdl2java -p com.jk.wdd.service.webservice -client localhost:8081/login/webservice/cxfUserService?wsdl
2:在resource⽬录下创建⼀个l
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="/schema/beans"
xmlns:xsi="/2001/XMLSchema-instance"
xmlns:p="/schema/p"
xmlns:context="/schema/context"
xmlns:tx="/schema/tx"
xmlns:mvc="/schema/mvc"
xmlns:aop="/schema/aop"
xmlns:jaxws="/jaxws"
xsi:schemaLocation="
/schema/beans
/schema/beans/spring-beans.xsd
/schema/context
/schema/context/spring-context.xsd
/schema/aop
/schema/aop/spring-aop.xsd
/schema/mvc
/schema/mvc/spring-mvc.xsd
/jaxws
/schemas/jaxws.xsd">
<!-- 导⼊cxf配置⽂件 -->
<import resource="classpath:META-INF/l" />
<import resource="classpath:META-INF/l" />
<import resource="classpath:META-INF/l" />
<!-- 这个class的包路径和类名和服务端提供web服务的接⼝⼀致-->
<bean id="client" class="com.jk.cqd.service.webservice.CxfUserServiceImpl" factory-bean="clientfactory" factory-method="create"/>
<bean id="clientfactory" class="f.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="com.jk.cqd.service.webservice.CxfUserServiceImpl"/>
<!-- 这个address⼀定要注意,正确的沒有?wsdl-->
<property name="address" value="192.168.126.1:8081/webservice/cxfUserService"/>
</bean>
<bean id="clientFy" class="com.jk.cqd.service.fanyiwebservice.TranslatorWebServiceSoap" factory-bean="clientfactoryFy" factory-method="create"/>
<bean id="clientFy" class="com.jk.cqd.service.fanyiwebservice.TranslatorWebServiceSoap" factory-bean="clientfactoryFy" factory-method="create"/>      <bean id="clientfactoryFy" class="f.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="com.jk.cqd.service.fanyiwebservice.TranslatorWebServiceSoap"/>
<!--        这个address⼀定要注意,正确的沒有?wsdl -->
<property name="address" value="www.webxml/WebServices/TranslatorWebService.asmx"/>
</bean>
</beans>
---------------------
作者:四⽅度爷
来源:CSDN
原⽂:blog.csdn/caiqiandu/article/details/88613938
版权声明:本⽂为博主原创⽂章,转载请附上博⽂链接!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。