function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gaurish Gopal GoelGaurish Gopal Goel 

Generating Apex Class from WSDL

I have a WSDL for some currency convertor application. I am trying to generate an apex class from wsdl.

 

When i tried to upload the wsdl, some errors came like Multiple Porttype, Multiple binding etc. After editing this wsdl somehow i fixed those errors and successfully parsed the wsdl.

 

But at the final step an error is occuring saying that: APEX GENERATION FAILED. UNABLE TO FIND SOAP 1.1 ADDRESS.

 

Please give some tips I am new to web services.

 

Best Answer chosen by Admin (Salesforce Developers) 
Satish_SFDCSatish_SFDC
I got this error message once and someone told me to use IE to download the WSDL.
Did not understand the logic behind it, but worked fine when i downloaded the WSDL file through IE.

Regards,
Satish Kumar

All Answers

Satish_SFDCSatish_SFDC
I got this error message once and someone told me to use IE to download the WSDL.
Did not understand the logic behind it, but worked fine when i downloaded the WSDL file through IE.

Regards,
Satish Kumar
This was selected as the best answer
Vinita_SFDCVinita_SFDC

Hello,

 

Apex class can be generated from the Soap 1.1 services, seems your WSDL contains only soap 1.2 services and that is why its failing. You will need WSDL which uses soap 1.1 service.

 

Use only SOAP, refer example:

 

http://stackoverflow.com/questions/7189134/wcf-basichttpbinding-where-can-i-find-soap1-1-in-wsdl

Gaurish Gopal GoelGaurish Gopal Goel
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://www.webserviceX.NET/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://www.webserviceX.NET/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://www.webserviceX.NET/">
      <s:element name="ConversionRate">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="FromCurrency" type="tns:Currency" />
            <s:element minOccurs="1" maxOccurs="1" name="ToCurrency" type="tns:Currency" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:simpleType name="Currency">
      </s:simpleType>
      <s:element name="ConversionRateResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="ConversionRateResult" type="s:double" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="double" type="s:double" />
    </s:schema>
  </wsdl:types>
  <wsdl:message name="ConversionRateSoapIn">
    <wsdl:part name="parameters" element="tns:ConversionRate" />
  </wsdl:message>
  <wsdl:message name="ConversionRateSoapOut">
    <wsdl:part name="parameters" element="tns:ConversionRateResponse" />
  </wsdl:message>
  <wsdl:message name="ConversionRateHttpGetIn">
    <wsdl:part name="FromCurrency" type="s:string" />
    <wsdl:part name="ToCurrency" type="s:string" />
  </wsdl:message>
  <wsdl:message name="ConversionRateHttpGetOut">
    <wsdl:part name="Body" element="tns:double" />
  </wsdl:message>
  <wsdl:message name="ConversionRateHttpPostIn">
    <wsdl:part name="FromCurrency" type="s:string" />
    <wsdl:part name="ToCurrency" type="s:string" />
  </wsdl:message>
  <wsdl:message name="ConversionRateHttpPostOut">
    <wsdl:part name="Body" element="tns:double" />
  </wsdl:message>
  <wsdl:portType name="CurrencyConvertorSoap">
    <wsdl:operation name="ConversionRate">
      
      <wsdl:input message="tns:ConversionRateSoapIn" />
      <wsdl:output message="tns:ConversionRateSoapOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:portType name="CurrencyConvertorHttpGet">
    <wsdl:operation name="ConversionRate">
      
      <wsdl:input message="tns:ConversionRateHttpGetIn" />
      <wsdl:output message="tns:ConversionRateHttpGetOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:portType name="CurrencyConvertorHttpPost">
    <wsdl:operation name="ConversionRate">
      
      <wsdl:input message="tns:ConversionRateHttpPostIn" />
      <wsdl:output message="tns:ConversionRateHttpPostOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="CurrencyConvertorSoap" type="tns:CurrencyConvertorSoap">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="ConversionRate">
      <soap:operation soapAction="http://www.webserviceX.NET/ConversionRate" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="CurrencyConvertorSoap12" type="tns:CurrencyConvertorSoap">
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="ConversionRate">
      <soap12:operation soapAction="http://www.webserviceX.NET/ConversionRate" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="CurrencyConvertorHttpGet" type="tns:CurrencyConvertorHttpGet">
    <http:binding verb="GET" />
    <wsdl:operation name="ConversionRate">
      <http:operation location="/ConversionRate" />
      <wsdl:input>
        <http:urlEncoded />
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="CurrencyConvertorHttpPost" type="tns:CurrencyConvertorHttpPost">
    <http:binding verb="POST" />
    <wsdl:operation name="ConversionRate">
      <http:operation location="/ConversionRate" />
      <wsdl:input>
        <mime:content type="application/x-www-form-urlencoded" />
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="CurrencyConvertor">
    <wsdl:port name="CurrencyConvertorSoap" binding="tns:CurrencyConvertorSoap">
      <soap:address location="http://www.webservicex.net/CurrencyConvertor.asmx" />
    </wsdl:port>
    <wsdl:port name="CurrencyConvertorSoap12" binding="tns:CurrencyConvertorSoap12">
      <soap12:address location="http://www.webservicex.net/CurrencyConvertor.asmx" />
    </wsdl:port>
    <wsdl:port name="CurrencyConvertorHttpGet" binding="tns:CurrencyConvertorHttpGet">
      <http:address location="http://www.webservicex.net/CurrencyConvertor.asmx" />
    </wsdl:port>
    <wsdl:port name="CurrencyConvertorHttpPost" binding="tns:CurrencyConvertorHttpPost">
      <http:address location="http://www.webservicex.net/CurrencyConvertor.asmx" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

 

Gaurish Gopal GoelGaurish Gopal Goel
I have posted the wsdl. Please check and tell which SOAP version is being used. It will be a great help.
Gaurish Gopal GoelGaurish Gopal Goel

Thanks SATISH for the solution. Thanks Vinita for the contribution. Satish's solution worked absolutely fine for me.

Gaurish Gopal GoelGaurish Gopal Goel
If we manage to find the logic behind this solution then it would be great.
Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Hi,

 

I found what the problem is!!

 

You are using a multiple portType for WSDL and it is not supported. Because, portType shows for getting in/out messages at a single port.

Anyways, I deleted other all the portypes and kept only one portType name="CurrencyConvertorSoap", and i completed parsing the wsdl without any errors and it has generated a class as well.

 

Am attaching the generated class as well as WSDL file i used to generate the class. Please find it as shown below.

 

WSDL:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tns="http://www.webserviceX.NET/" xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
targetNamespace="http://www.webserviceX.NET/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">

 

  <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://www.webserviceX.NET/">
      <s:element name="ConversionRate">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="FromCurrency" type="tns:Currency" />
            <s:element minOccurs="1" maxOccurs="1" name="ToCurrency" type="tns:Currency" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:simpleType name="Currency">
      </s:simpleType>
      <s:element name="ConversionRateResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="ConversionRateResult" type="s:double" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="double" type="s:double" />
    </s:schema>
  </wsdl:types>


  <wsdl:message name="ConversionRateSoapIn">
    <wsdl:part name="parameters" element="tns:ConversionRate" />
  </wsdl:message>
  <wsdl:message name="ConversionRateSoapOut">
    <wsdl:part name="parameters" element="tns:ConversionRateResponse" />
  </wsdl:message>


 <wsdl:portType name="CurrencyConvertorSoap">
    <wsdl:operation name="ConversionRate">     
      <wsdl:input message="tns:ConversionRateSoapIn" />
      <wsdl:output message="tns:ConversionRateSoapOut" />
    </wsdl:operation>
  </wsdl:portType>


  <wsdl:binding name="CurrencyConvertorSoap" type="tns:CurrencyConvertorSoap">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="ConversionRate">
      <soap:operation soapAction="http://www.webserviceX.NET/ConversionRate" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding> 


  <wsdl:service name="CurrencyConvertor">
    <wsdl:port name="CurrencyConvertorSoap" binding="tns:CurrencyConvertorSoap">
      <soap:address location="http://www.webservicex.net/CurrencyConvertor.asmx" />
    </wsdl:port>     
  </wsdl:service>
</wsdl:definitions>

 

 

Generated class:

//Generated by wsdl2apex

public class wwwWebservicexNet {
    public class CurrencyConvertorSoap {
        public String endpoint_x = 'http://www.webservicex.net/CurrencyConvertor.asmx';
        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://www.webserviceX.NET/', 'wwwWebservicexNet'};
        public Double ConversionRate(String FromCurrency,String ToCurrency) {
            wwwWebservicexNet.ConversionRate_element request_x = new wwwWebservicexNet.ConversionRate_element();
            wwwWebservicexNet.ConversionRateResponse_element response_x;
            request_x.FromCurrency = FromCurrency;
            request_x.ToCurrency = ToCurrency;
            Map<String, wwwWebservicexNet.ConversionRateResponse_element> response_map_x = new Map<String, wwwWebservicexNet.ConversionRateResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'http://www.webserviceX.NET/ConversionRate',
              'http://www.webserviceX.NET/',
              'ConversionRate',
              'http://www.webserviceX.NET/',
              'ConversionRateResponse',
              'wwwWebservicexNet.ConversionRateResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.ConversionRateResult;
        }
    }
    public class ConversionRate_element {
        public String FromCurrency;
        public String ToCurrency;
        private String[] FromCurrency_type_info = new String[]{'FromCurrency','http://www.webserviceX.NET/',null,'1','1','false'};
        private String[] ToCurrency_type_info = new String[]{'ToCurrency','http://www.webserviceX.NET/',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://www.webserviceX.NET/','true','false'};
        private String[] field_order_type_info = new String[]{'FromCurrency','ToCurrency'};
    }
    public class ConversionRateResponse_element {
        public Double ConversionRateResult;
        private String[] ConversionRateResult_type_info = new String[]{'ConversionRateResult','http://www.webserviceX.NET/',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://www.webserviceX.NET/','true','false'};
        private String[] field_order_type_info = new String[]{'ConversionRateResult'};
    }
}

 

 

Hope so this helps you...!

Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.

Gaurish Gopal GoelGaurish Gopal Goel
Great work and Thanks a lot. But Satish has already provided the solution I was looking for. For multiple porttypes and binding, I have clearly mentioned in my post that I resolved those errors and successfully parsed the wsdl. But the error was occuring at the final step in Apex code generation. When I tried Satish's solution it worked.
I appreciate your help as well. Thanks again.
Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Good to see your reply. Thank you.

Gaurish Gopal GoelGaurish Gopal Goel
Although I have Kudoed you because you made an awesome effort by generating
the apex as well. :-)
looking forward for more help from you in future.

--
With Regards
Gaurish Gopal Goel
Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Sure, thanks again.

Pragnesh KariaPragnesh Karia
Please help me out here , i am able to import WSDL in 'Apex Class' , and my generated class is as below

//Generated by wsdl2apex

public class wwwWebservicexNetCurrency {
    public class ConversionRate_element {
        public String FromCurrency;
        public String ToCurrency;
        private String[] FromCurrency_type_info = new String[]{'FromCurrency','http://www.webserviceX.NET/',null,'1','1','false'};
        private String[] ToCurrency_type_info = new String[]{'ToCurrency','http://www.webserviceX.NET/',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://www.webserviceX.NET/','true','false'};
        private String[] field_order_type_info = new String[]{'FromCurrency','ToCurrency'};
    }
    public class ConversionRateResponse_element {
        public Double ConversionRateResult;
        private String[] ConversionRateResult_type_info = new String[]{'ConversionRateResult','http://www.webserviceX.NET/',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://www.webserviceX.NET/','true','false'};
        private String[] field_order_type_info = new String[]{'ConversionRateResult'};
    }
    public class CurrencyConvertorSoap {
        public String endpoint_x = 'http://www.webservicex.net/CurrencyConvertor.asmx';
        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://www.webserviceX.NET/', 'wwwWebservicexNetCurrency'};
        public Double ConversionRate(String FromCurrency,String ToCurrency) {
            wwwWebservicexNetCurrency.ConversionRate_element request_x = new wwwWebservicexNetCurrency.ConversionRate_element();
            request_x.FromCurrency = FromCurrency;
            request_x.ToCurrency = ToCurrency;
            wwwWebservicexNetCurrency.ConversionRateResponse_element response_x;
            Map<String, wwwWebservicexNetCurrency.ConversionRateResponse_element> response_map_x = new Map<String, wwwWebservicexNetCurrency.ConversionRateResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'http://www.webserviceX.NET/ConversionRate',
              'http://www.webserviceX.NET/',
              'ConversionRate',
              'http://www.webserviceX.NET/',
              'ConversionRateResponse',
              'wwwWebservicexNetCurrency.ConversionRateResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.ConversionRateResult;
        }
    }
}

Now i am trying to call this Apex Class in Developer console.

wwwWebservicexNetCurrency.CurrencyConvertorSoap proxyClass = new wwwWebservicexNetCurrency.CurrencyConvertorSoap();
String retVal = proxyClass.ConversionRate('INR','USD');
System.debug(retVal);
it is giving error like, "Illegal assignment from Double to String"


I am stuck here, any help would be appreciated.

Regards,

Pragnesh Karia







Gaurish Gopal GoelGaurish Gopal Goel
The reason why you are getting this error is that you are storing the result of a method in a string type of variable but the return type of the method is Double type.
wwwWebservicexNetCurrency.CurrencyConvertorSoap proxyClass = new wwwWebservicexNetCurrency.CurrencyConvertorSoap();
Double retVal = proxyClass.ConversionRate('INR','USD');        //Replace string with Double.
System.debug(retVal);