当前位置:   article > 正文

SpringBoot集成WebService接口开发_springboot @webservice targetnamespace

springboot @webservice targetnamespace

1、导入依赖pom.xml

  1. <!-- cxf接口开始 -->
  2. <dependency>
  3. <groupId>org.apache.cxf</groupId>
  4. <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
  5. <version>3.2.5</version>
  6. </dependency>
  7. <!-- cxf接口结束 -->

2、加入配置文件

 
  1. package com.gccloud.idc.order.handle.center.config;
  2. import com.gccloud.idc.order.handle.center.cxf.service.impl.WebServiceImpl;
  3. import com.gccloud.idc.order.handle.center.cxf.service.impl.WsSheetServiceImpl;
  4. import org.apache.cxf.Bus;
  5. import org.apache.cxf.jaxws.EndpointImpl;
  6. import org.apache.cxf.bus.spring.SpringBus;
  7. import org.apache.cxf.transport.servlet.CXFServlet;
  8. import org.springframework.boot.web.servlet.ServletRegistrationBean;
  9. import org.springframework.context.annotation.Bean;
  10. import org.springframework.context.annotation.Configuration;
  11. import javax.xml.ws.Endpoint;
  12. /**
  13. * @Author
  14. * @Date 2021/6/17 14:47
  15. * @Version 1.0
  16. */
  17. @Configuration
  18. public class WebServiceConfig {
  19. @Bean
  20. public ServletRegistrationBean disServlet(){
  21. return new ServletRegistrationBean(new CXFServlet() , "/services/*");
  22. }
  23. @Bean
  24. public Endpoint endpoint() {
  25. EndpointImpl endpoint = new EndpointImpl(springBus(),new WebServiceImpl());
  26. endpoint.publish("/NetbarServices");//接口发布在 /NetbarServices 目录下
  27. return endpoint;
  28. }
  29. @Bean(name = Bus.DEFAULT_BUS_ID)
  30. public SpringBus springBus() {
  31. return new SpringBus();
  32. }
  33. }

3、测试类

  1. package com.gccloud.idc.order.handle.center.cxf.service;
  2. import javax.jws.WebMethod;
  3. import javax.jws.WebParam;
  4. import javax.jws.WebService;
  5. /**
  6. * @Author
  7. * @Date 2021/6/17 14:53
  8. * @Version 1.0
  9. */
  10. @WebService(name = "WebServices")
  11. public interface WebServices {
  12. /**
  13. * 测试方法
  14. *
  15. * @param name
  16. * @return
  17. */
  18. @WebMethod
  19. String sayHello(@WebParam(name = "userName") String name);
  20. }

 

  1. package com.gccloud.idc.order.handle.center.cxf.service.impl;
  2. import com.gccloud.idc.order.handle.center.cxf.service.WebServices;
  3. import javax.jws.WebService;
  4. /**
  5. * @Author
  6. * @Date 2021/6/17 14:54
  7. * @Version 1.0
  8. */
  9. @WebService(serviceName = "WebServices", targetNamespace ="")
  10. public class WebServiceImpl implements WebServices {
  11. @Override
  12. public String sayHello(String name) {
  13. return "hello , " + name;
  14. }
  15. }

 4、测试接口

在浏览器输入:http://localhost:8102/orderHandleCenter/services/NetbarServices?wsdl

5、webService接口注释含义

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

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/57701
推荐阅读
相关标签
  

闽ICP备14008679号