A WSDL on the web can test the code generation against this case


      <wsdl:definitions name="HelloWorldService" targetNamespace="http://test.demo1/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://test.demo1/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <wsdl:types>
        <xs:schema elementFormDefault="unqualified" targetNamespace="http://test.demo1/" version="1.0" xmlns:tns="http://test.demo1/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xs:element name="sayHello" type="tns:sayHello"/>
            <xs:element name="sayHelloResponse" type="tns:sayHelloResponse"/>
            <xs:complexType name="sayHello">
                <xs:sequence>
                    <xs:element minOccurs="0" name="arg0" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
            <xs:complexType name="sayHelloResponse">
                <xs:sequence>
                    <xs:element minOccurs="0" name="return" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
        </xs:schema>
    </wsdl:types>
    <wsdl:message name="sayHelloResponse">
        <wsdl:part element="tns:sayHelloResponse" name="parameters">
        </wsdl:part>
    </wsdl:message>
    <wsdl:message name="sayHello">
        <wsdl:part element="tns:sayHello" name="parameters">
        </wsdl:part>
    </wsdl:message>
    <wsdl:portType name="HelloWorld">
        <wsdl:operation name="sayHello">
            <wsdl:input message="tns:sayHello" name="sayHello">
            </wsdl:input>
            <wsdl:output message="tns:sayHelloResponse" name="sayHelloResponse">
            </wsdl:output>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="HelloWorldServiceSoapBinding" type="tns:HelloWorld">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="sayHello">
            <soap:operation soapAction="" style="document"/>
            <wsdl:input name="sayHello">
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output name="sayHelloResponse">
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="HelloWorldService">
        <wsdl:port binding="tns:HelloWorldServiceSoapBinding" name="HelloWorldPort">
            <soap:address location="http://localhost:8080/helloWorld"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>
Copy the code

1.The JDK comes with itwsimport

Refer to generating client code through WSDL

PS: Run the wsimport command in the java.bin directory

Wsimport [options] <WSDL_URI> \ -b <path> Specifies the JAXWS/JAXB binding file or additional schema (each <path> must have its own -B) -b <jaxbOption> passes this option to the JAXB schema compiler -catalog <file> Specify that the directory files used to resolve external entity references support the TR9401, XCatalog, and OASIS XML directory formats. -d <directory> Specifies where to put the generated output file. -encoding <encoding> Specifies the character encoding to be used in the source file. -extension Allows vendor extensions. -help Displays help -httpproxy:<host>:<port> Specifies HTTP proxy server (port defaults to 8080) -keep Keeps generated files -p < PKG > -s <directory> Specifies where to put the generated source files. -target <version> Generates code for the given JAXWS specification version by default. The default value is 2.2 and the accepted value is 2.0. 2.1 and 2.2 For example, -verbose Output message about what the compiler is doing -version Output version information -wsdlLocation <location> @ WebServiceClient. WsdlLocation value - clientjar < jarfile > create an Artifact generated jar files and WSDL metadata required to invoke the Web service. -generateJWS Generates the stump JWS implementation file -implDestDir <directory> Specifies the location where the JWS implementation file is generated. -implServiceName <name> Local part of the service name of the generated JWS implementation -implportName <name> Local part of the generated JWS implementation port name \ extension: -xAdditionalHeaders Mapping headers are not bound to request or response messages are not bound to Java method parameters -xAuthFile File used to transmit authorization information in the following format: http://username:[email protected]/stock?wsdl -xdebug Output debugging information. -xno-Addressing - Databinding Allows W3C EndpointReferenceType Binding to Java -xnocompile Does not compile generated Java files -xdisableAuthenticator disables the validator used by jax-WS RI, Will be ignored - Xauthfile option (if set) - XdisableSSLHostnameVerification WSDL are disable SSL host name validation \ sample: wsimport stock.wsdl -b stock.xml -b stock.xjb wsimport -d generated http://example.org/stock?wsdlCopy the code

2,Wsdl2java of apache-CXF

  1. Binary distribution for Apache CXF download

  1. Download the file and decompress it to a specified directory

    E:\service\webservice\apache- CXF - 3.3.11Copy the code

  1. Add apache-cxf-*/bin to the system variable path

    E:\service\webservice\apache- CXF - 3.3.11\bin
    Copy the code

  2. CMD run the wsdl2java -help command to check whether the configuration is normal

  1. Run the wsdl2java command in the apache-cxf-*/bin directory

    wsdl2java -encoding utf-8 -d The directory where the file is generated WSDL file address or WSDL URL address

    PS E:\service\webservice\apache-cxf-3.3.11\bin> wsdl2java -encoding utf-8 -p com.example.order -d D:\ideaProject\htlm\demo\web-service-demo\src\main\java D:\ideaProject\htlm\demo\web-service-demo\src\main\resources\Air.wsdl
    Copy the code
Wsdl2java [options] <WSDL_URI> \ where [options] includes: -p <[wsdl-namespace =]package-name>* Specifies the Name of the Java package to use for the generated code -d <output-directory> Specifies the directory where the generated code is to be placed. -server Specifies the generated server code. -client Specifies the generated client code -autoNameResolution specifies that the tool will attempt to resolve naming conflicts for classes without requiring binding customization. \ Example: wsdl2java -d d :\demo d :\ t.wssdlCopy the code

3, IDEA built-in plug-in generation

  1. Idea menu bar select Tools->WebServices->Generate Java Code From Wsdl

Q&A

  1. When IDEA is generated, the following error may occur if the project is compiled using JDK11. Please use JDK8. Or use the second generation

  1. Indicates that a class/interface with the same name is already in use. Use class customization to resolve this conflict

    For the second generation, simply add the -autonameresolution argument to the command

    wsdl2java -autoNameResolution -d D:\demo D:\t.wsdl
    Copy the code