SOAP web service – Creating a class from WSDL

SOAP web service – How to creating a class from WSDL document?

SOAP web service class can be generated automatically by using WSDL document. Generating WSDL document allows Salesforce developers to make callouts to the external web service in their Apex code.

Follow below steps to generate apex class from a WSDL:

1.Go to Apex Classes form setup menu.
2.Click “Generate from WSDL” button.

SOAP Web Service 1
3.Select WSDL document(XML file) you are using to generate apex class by clikcing choose file lookup button. This WSDL document is base to generate apex class.

SOAP Web Service 2Here I selected Test-SOAP webservice WSDL file which is rounded by red color line in the above image. You can select WSDL by clicking on choose File button.

4.Click Parse WSDL button which is highleted in the above image to verify WSDL document contents. It generates default class name based on WSDL document. It report errors in case of the WSDL contains schema types or constructs that aren’t supported by Apex classes, or if the resulting classes exceed the 1-million-character limit on Apex classes. For example, the Salesforce SOAP API.

SOAP Web Service 3You can rename the class. And click on Generate Apex button. The final page of the wizard shows which classes were successfully generated, along with any errors from other classes. The page also provides a link to view successfully generated code.

Generated Apex classes include stub and type classes for calling the third-party Web service represented by the WSDL document. These classes allow you to call the external Web service from Apex.

When you generate Apex classes by using WSDL, it generated 2 classes, one is with given name for synchronus callouts and other is prefixed with Async for asynchronus callouts.

SOAP Web Service 4

Refere here to know more about SOAP callouts: