• 基于Java的WebService客户端


    本文续接上文 基于Java的WebService服务端 

    ⒈访问服务端的暴露地址,如下图,下载相关服务的WSDL文件,用于生成相关的客户端代码。

    ⒉将服务的WSDL文件拷贝到项目的静态目录中。

    ⒊在pom文件中添加相关依赖

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.6.1</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>cn.coreqi</groupId>
        <artifactId>wsdl_client</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>wsdl_client</name>
        <description>wsdl_client</description>
        <properties>
            <java.version>1.8</java.version>
        </properties>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <scope>runtime</scope>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-configuration-processor</artifactId>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
    <!--            <scope>test</scope>-->
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <excludes>
                            <exclude>
                                <groupId>org.projectlombok</groupId>
                                <artifactId>lombok</artifactId>
                            </exclude>
                        </excludes>
                    </configuration>
                </plugin>
    
                <plugin>
                    <groupId>org.apache.cxf</groupId>
                    <artifactId>cxf-codegen-plugin</artifactId>
                    <version>3.4.5</version>
                    <executions>
                        <execution>
                            <id>generate-sources</id>
                            <phase>generate-sources</phase>
                            <configuration>
                                <encoding>UTF-8</encoding>
                                <sourceRoot>${project.basedir}/src/main/java/</sourceRoot>
                                <defaultOptions>
    <!--                                <extraargs>-->
    <!--                                    <extraarg>-impl</extraarg>-->
    <!--                                    <extraarg>-verbose</extraarg>-->
    <!--                                    <extraarg>-validate</extraarg>-->
    <!--                                    <extraarg>-client</extraarg>-->
    <!--                                </extraargs>-->
                                </defaultOptions>
                                <wsdlOptions>
                                    <wsdlOption>
                                        <wsdl>${project.basedir}/src/main/resources/wsdl/sayHello.wsdl</wsdl>
                                        <extraargs>
                                            <extraarg>-p</extraarg>
                                            <extraarg>cn.coreqi.wsdl_client.services.sayHello</extraarg>
                                        </extraargs>
                                    </wsdlOption>
                                    <wsdlOption>
                                        <wsdl>${project.basedir}/src/main/resources/wsdl/getPrice.wsdl</wsdl>
                                        <extraargs>
                                            <extraarg>-p</extraarg>
                                            <extraarg>cn.coreqi.wsdl_client.services.getPrice</extraarg>
                                        </extraargs>
                                    </wsdlOption>
                                </wsdlOptions>
                            </configuration>
                            <goals>
                                <goal>wsdl2java</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    
    </project>

    ⒋调用maven 的安装命令即可生成相关代码,如下图所示。【也可以使用apache-cxf工具进行生成,手动拷贝到项目中,这里使用的是maven插件】

  • 相关阅读:
    11 dubbo monitor
    svn ignore忽略文件
    Java Core Dump分析过程
    10 其他
    9 jenkins
    8 jenkins
    7 nhorizons项目结构
    6 发布个人项目到私服
    5 jenkins使用gitee
    4 Linux安装git
  • 原文地址:https://www.cnblogs.com/fanqisoft/p/16087216.html
Copyright © 2020-2023  润新知