---
schema_version: "1"
id: 4a05f08e2c7a2213e2e14f36831cd4eba6b344a4d7d6f5b46f5d455ebba67844
title: Generated WSDL2Apex Code
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/apex_callouts_wsdl2apex_gen_code.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_wsdl2apex_gen_code.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 1b684e1ca90b64fdd6f8bd506dc1900f51b0f70667457ab45e067288a89036d5
description: You can generate Apex classes from a WSDL document using the WSDL2Apex tool. The WSDL2Apex tool is open source and available on GitHub.
---
# Generated WSDL2Apex Code

You can generate Apex classes from a WSDL document using the WSDL2Apex tool. The WSDL2Apex tool is open source and available on GitHub.

You can find and contribute to the WSDL2Apex source code in the [WSDL2Apex repository on GitHub](https://github.com/forcedotcom/WSDL2Apex "HTML (New Window)").

The following example shows how an Apex class is created from a WSDL document. The Apex class is auto-generated for you when you import the WSDL.

The following code shows a sample WSDL document.

<wsdl:definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:s="http://www.w3.org/2001/XMLSchema"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:tns="http://doc.sample.com/docSample"
    targetNamespace="http://doc.sample.com/docSample"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">

<!-- Above, the schema targetNamespace maps to the Apex class name. -->

<!-- Below, the type definitions for the parameters are listed. 
    Each complexType and simpleType parameteris mapped to an Apex class inside the parent class for the WSDL.
    Then, each element in the complexType is mapped to a public field inside the class. -->

    <wsdl:types\>
        <s:schema elementFormDefault="qualified"
            targetNamespace="http://doc.sample.com/docSample">
            <s:element name="EchoString">
                <s:complexType\>
                    <s:sequence\>
                        <s:element minOccurs="0" maxOccurs="1" name="input" type="s:string" />
                    </s:sequence\>
                </s:complexType\>
            </s:element\>
            <s:element name="EchoStringResponse">
                <s:complexType\>
                    <s:sequence\>
                        <s:element minOccurs="0" maxOccurs="1" name="EchoStringResult"
                            type="s:string" />
                    </s:sequence\>
                </s:complexType\>
            </s:element\>
        </s:schema\>
    </wsdl:types\>

<!--The stub below defines operations. -->

    <wsdl:message name="EchoStringSoapIn">
        <wsdl:part name="parameters" element="tns:EchoString" />
    </wsdl:message\>
    <wsdl:message name="EchoStringSoapOut">
        <wsdl:part name="parameters" element="tns:EchoStringResponse" />
    </wsdl:message\>
    <wsdl:portType name="DocSamplePortType">
        <wsdl:operation name="EchoString">
            <wsdl:input message="tns:EchoStringSoapIn" />
            <wsdl:output message="tns:EchoStringSoapOut" />
        </wsdl:operation\>
    </wsdl:portType\>

    <!--The code below defines how the types map to SOAP. -->

    <wsdl:binding name="DocSampleBinding" type="tns:DocSamplePortType">
        <wsdl:operation name="EchoString">
            <soap:operation soapAction="urn:dotnet.callouttest.soap.sforce.com/EchoString"
                style="document" />
            <wsdl:input\>
                <soap:body use="literal" />
            </wsdl:input\>
            <wsdl:output\>
                <soap:body use="literal" />
            </wsdl:output\>
        </wsdl:operation\>
    </wsdl:binding\>

<!-- Finally, the code below defines the endpoint, which maps to the endpoint in the class -->

    <wsdl:service name="DocSample">
        <wsdl:port name="DocSamplePort" binding="tns:DocSampleBinding">
            <soap:address location="http://YourServer/YourService" />
        </wsdl:port\>
    </wsdl:service\>
</wsdl:definitions\>

From this WSDL document, the following Apex class is auto-generated. The class name docSample is the name you specify when importing the WSDL.

//Generated by wsdl2apex

public with sharing class docSample {
    public with sharing class EchoStringResponse\_element {
        public String EchoStringResult;
        private String\[\] EchoStringResult\_type\_info = new String\[\]{
                            'EchoStringResult',
                            'http://doc.sample.com/docSample',
                             null,'0','1','false'};
        private String\[\] apex\_schema\_type\_info = new String\[\]{
                             'http://doc.sample.com/docSample',
                             'true','false'};
        private String\[\] field\_order\_type\_info = new String\[\]{
                             'EchoStringResult'};
    }
    public with sharing class EchoString\_element {
        public String input;
        private String\[\] input\_type\_info = new String\[\]{
                              'input',
                              'http://doc.sample.com/docSample',
                               null,'0','1','false'};
        private String\[\] apex\_schema\_type\_info = new String\[\]{
                               'http://doc.sample.com/docSample',
                               'true','false'};
        private String\[\] field\_order\_type\_info = new String\[\]{'input'};
    }
    public with sharing class DocSamplePort {
        public String endpoint\_x = 'http://YourServer/YourService';
        public Map<String,String\> inputHttpHeaders\_x;
        public Map<String,String\> outputHttpHeaders\_x;
        public String clientCertName\_x;
        public String clientCert\_x;
        public String clientCertPasswd\_x;
        public Integer timeout\_x;
        private String\[\] ns\_map\_type\_info = new String\[\]{
                          'http://doc.sample.com/docSample', 'docSample'};
        public String EchoString(String input) {
            docSample.EchoString\_element request\_x = new 
                                           docSample.EchoString\_element();
            request\_x.input = input;
            docSample.EchoStringResponse\_element response\_x;
            Map<String, docSample.EchoStringResponse\_element> response\_map\_x = 
                       new Map<String, docSample.EchoStringResponse\_element>();
            response\_map\_x.put('response\_x', response\_x);
            WebServiceCallout.invoke(
              this,
              request\_x,
              response\_map\_x,
              new String\[\]{endpoint\_x,
              'urn:dotnet.callouttest.soap.sforce.com/EchoString',
              'http://doc.sample.com/docSample',
              'EchoString',
              'http://doc.sample.com/docSample',
              'EchoStringResponse',
              'docSample.EchoStringResponse\_element'}
            );
            response\_x = response\_map\_x.get('response\_x');
            return response\_x.EchoStringResult;
        }
    }
}

Note the following mappings from the original WSDL document:

- The WSDL target namespace maps to the Apex class name.
- Each complex type becomes a class. Each element in the type is a public field in the class.
- The WSDL port name maps to the stub class.
- Each operation in the WSDL maps to a public method.

You can use the auto-generated docSample class to invoke external Web services. The following code calls the echoString method on the external server.

docSample.DocSamplePort stub = new docSample.DocSamplePort();
String input = 'This is the input string';
String output = stub.EchoString(input);

- [Next →](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_wsdl2apex_testing.htm "Test Web Service Callouts")