赞
踩
1、导入依赖pom.xml
- <!-- cxf接口开始 -->
- <dependency>
- <groupId>org.apache.cxf</groupId>
- <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
- <version>3.2.5</version>
- </dependency>
- <!-- cxf接口结束 -->
2、加入配置文件
- package com.gccloud.idc.order.handle.center.config;
-
- import com.gccloud.idc.order.handle.center.cxf.service.impl.WebServiceImpl;
- import com.gccloud.idc.order.handle.center.cxf.service.impl.WsSheetServiceImpl;
- import org.apache.cxf.Bus;
- import org.apache.cxf.jaxws.EndpointImpl;
- import org.apache.cxf.bus.spring.SpringBus;
- import org.apache.cxf.transport.servlet.CXFServlet;
- import org.springframework.boot.web.servlet.ServletRegistrationBean;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
-
- import javax.xml.ws.Endpoint;
-
- /**
- * @Author
- * @Date 2021/6/17 14:47
- * @Version 1.0
- */
- @Configuration
- public class WebServiceConfig {
- @Bean
- public ServletRegistrationBean disServlet(){
- return new ServletRegistrationBean(new CXFServlet() , "/services/*");
- }
- @Bean
- public Endpoint endpoint() {
- EndpointImpl endpoint = new EndpointImpl(springBus(),new WebServiceImpl());
- endpoint.publish("/NetbarServices");//接口发布在 /NetbarServices 目录下
- return endpoint;
- }
-
- @Bean(name = Bus.DEFAULT_BUS_ID)
- public SpringBus springBus() {
- return new SpringBus();
- }
- }

3、测试类
- package com.gccloud.idc.order.handle.center.cxf.service;
-
- import javax.jws.WebMethod;
- import javax.jws.WebParam;
- import javax.jws.WebService;
-
- /**
- * @Author
- * @Date 2021/6/17 14:53
- * @Version 1.0
- */
- @WebService(name = "WebServices")
- public interface WebServices {
- /**
- * 测试方法
- *
- * @param name
- * @return
- */
- @WebMethod
- String sayHello(@WebParam(name = "userName") String name);
- }

- package com.gccloud.idc.order.handle.center.cxf.service.impl;
-
- import com.gccloud.idc.order.handle.center.cxf.service.WebServices;
-
- import javax.jws.WebService;
-
- /**
- * @Author
- * @Date 2021/6/17 14:54
- * @Version 1.0
- */
- @WebService(serviceName = "WebServices", targetNamespace ="")
- public class WebServiceImpl implements WebServices {
- @Override
- public String sayHello(String name) {
- return "hello , " + name;
- }
- }

4、测试接口
在浏览器输入:http://localhost:8102/orderHandleCenter/services/NetbarServices?wsdl

5、webService接口注释含义
- @WebService(targetNamespace="http://suishenyunwei.interfaces.eoms.boco.com",serviceName = "/sSYWCommandTaskOptService")
- targetNamespace调用方调用的时候会把命名空间带过来 你这个地方要和它带过来的地址保持一致
- 实现 Web Service 的 Java 类必须指定@WebService 或 @WebServiceProvider 注释。不能同时提供这两种注释。
- @WebService中
- name:wsdl:portType 的名称。缺省值为Java 类或接口的非限定名称。(字符串);
- targetNamespace:指定从 Web Service 生成的 WSDL 和 XML 元素的XML 名称空间。缺省值为从包含该 Web Service 的包名映射的名称空间。(字符串);
- serviceName:指定 Web Service 的服务名称: wsdl:service。缺省值为Java 类的简单名称 + Service。(字符串);
- endpointInterface:指定用于定义服务的抽象 Web Service约定的服务端点接口的限定名。如果指定了此限定名,那么会使用该服务端点接口来确定抽象 WSDL 约定。(字符串);
- portName:wsdl:portName。缺省值为WebService.name+ Port。(字符串);
- wsdlLocation:指定用于定义 Web Service 的 WSDL 文档的 Web地址。Web 地址可以是相对路径或绝对路径。(字符串)
- @WebMethod注释表示作为一项 Web Service操作的方法,仅支持在使用 @WebService注释来注释的类上使用 @WebMethod 注释。
- 注释目标:方法
- operationName:指定与此方法相匹配的 wsdl:operation 的名称。缺省值为Java 方法的名称。(字符串);
- action:定义此操作的行为。对于 SOAP 绑定,此值将确定 SOAPAction头的值。缺省值为 Java 方法的名称。(字符串);
- exclude:指定是否从 Web Service中排除某一方法。缺省值为 false。
- @Oneway注释将一个方法表示为只有输入消息而没有输出消息的Web Service 单向操作。将此注释应用于客户机或服务器服务端点接口(SEI)上的方法
- @WebParam注释用于定制从单个参数至 WebService 消息部件和 XML 元素的映射。
- 注释目标:参数
- name:参数的名称。如果操作是远程过程调用(RPC)类型并且未指定 partName 属性,那么这是用于表示参数的 wsdl:part 属性的名称。如果操作是文档类型或者参数映射至某个头,那么 -name 是用于表示该参数的XML 元素的局部名称。如果操作是文档类型、参数类型为 BARE 并且方式为 OUT 或 INOUT,那么必须指定此属性。(字符串);
- partName:定义用于表示此参数的 wsdl:part属性的名称。仅当操作类型为RPC 或者操作是文档类型并且参数类型为 BARE 时才使用此参数。(字符串);
- targetNamespace:指定参数的 XML 元素的 XML 名称空间。当属性映射至 XML元素时,仅应用于文档绑定。缺省值为 Web Service 的 targetNamespace。(字符串);
- header:指定参数是在消息头还是消息体中。缺省值为 false。(布尔值);
-
-
- 用sopUI测试报错试试
- <![CDATA[" 开始,由 "]]>" 结束: 用这个包起来试试 把arg0节点包在里面 如果这样不行 再试试在arg0后面包起来

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。