```xml
<dependency>
  <groupId>org.noear</groupId>
  <artifactId>solon-web-webservices</artifactId>
</dependency>
```


### 1、描述

此插件基于 apache.cxf 适配，提供方便的 webservices 体验支持。内部有 java spi，所以：

* 不能使用打包【方式1】（或者，添加合并 spi 的辅助配置）；
* 需要使用打包【方式2】或【方式3】（依赖包的 jar 会保留）。

示例源码详见：

* [demo3082-wsdl_solon](https://gitee.com/noear/solon-examples/tree/main/3.Solon-Web/demo3082-wsdl_solon)


### 2、服务端示例

服务端需要与 solon-server-jetty 或者 solon-server-unertow 或者 war 部署方式（目前基于 servlet 实现），配合使用。

* 添加配置（指定 web service 路径段）

```yaml
server.webservices.path: "/ws/" #默认为 ws
```

* 添加服务代码

```java
public class ServerTest {
    public static void main(String[] args) {
        Solon.start(ServerTest.class, args);
    }

    //@BindingType(SOAPBinding.SOAP12HTTP_BINDING) //可选，声明版本特性
    @WebService(serviceName = "HelloService", targetNamespace = "http://demo.solon.io")
    public static class HelloServiceImpl {
        public String hello(String name) {
            return "hello " + name;
        }
    }
}
```

启动后，可以通过 `http://localhost:8080/ws/HelloService?wsdl` 查看 wsdl 信息。

### 3、客户端示例

(没有环境依赖)

* 手写模式

```java
public class ClientTest {
    public static void main(String[] args) {
        String wsAddress = "http://localhost:8080/ws/HelloService";
        HelloService helloService = WebServiceHelper.createWebClient(wsAddress, HelloService.class);

        System.out.println("rst::" + helloService.hello("noear"));
    }

    @WebService(serviceName = "HelloService", targetNamespace = "http://demo.solon.io")
    public interface HelloService {
        @WebMethod
        String hello(String name);
    }
}
```

* 容器模式

使用 `@WebServiceReference` 注解，直接注入服务。

```java
//测试控制器
@Controller
public class DemoController {
    @WebServiceReference("http://localhost:8080/ws/HelloService")
    private HelloService helloService;

    @Mapping("/test")
    public String test() {
        return helloService.hello("noear");
    }
}

//配置 WebService 接口
@WebService(serviceName = "HelloService", targetNamespace = "http://demo.solon.io")
public interface HelloService {
    @WebMethod
    String hello(String name);
}

//启动 Solon
public class ClientTest {
    public static void main(String[] args) {
        Solon.start(ClientTest.class, args);
    }
}
```