7

I have a few questions regarding Named Credentials. I need to perform a SOAP based call out to an external system from Sales Force. I used the wsdl2apex function to generate the class for the call out. When I started integrating this class into my process I got to thinking about securely storing the username and password for the call out, which led me to discover Named Credentials. Question is, can Named Credentials be used in the auto-generated apex class? If so, could you please provide an example?

Thanks in advance

2
  • What type of authentication does the web service support? OAuth2 isn't going to be a direct option with Wsdl2Apex. Are you using basic password authentication? Commented May 1, 2015 at 1:56
  • For what it's worth, I have a tool similar to Wsdl2Apex that can generate raw HttpRequest send calls from the WSDL. These could be updated to use Named Credentials in theory (assuming the web service supports basic password authentication). Commented May 1, 2015 at 1:58

1 Answer 1

7

UPDATE for Winter `16 - Simplify Development of Web Service Callouts by Using Named Credentials


Short answer. No, it doesn't appear Named Credentials are supported by Wsdl2Apex.

I created minimal Named Credential for a public webservicex web service that doesn't require authentication (to check if it will work for the endpoint URL).

enter image description here

Then I tried to change the wsdl2Apex generated classes endpoint_x to use it.

wwwWebservicexNet.GlobalWeatherSoap ws = new wwwWebservicexNet.GlobalWeatherSoap();
ws.endpoint_x = 'callout:webservicex';

string weather = ws.GetWeather('Paris / Le Bourget', 'France');
System.debug(weather);

This gives:

System.CalloutException: IO Exception: unknown protocol: callout


In the past I've used protected custom settings within a managed package to store the credentials that are passed to a SOAP web service. As a hierarchy setting I can store Org, Profile, or User level credentials. When deployed as a managed package the credentials can only be accessed by the Apex defined within the package (this includes setting the values as well as retrieval).


Out of interest, I used the FuseIT SFDC Explorer (Disclosure: Made by my current employer) to generate a method from the WSDL that uses HttpRequest and a manual SOAP body rather than WebServiceCallout.invoke.

wwwWebservicexNet.GlobalWeatherSoap ws = new wwwWebservicexNet.GlobalWeatherSoap();
ws.endpoint_x = 'callout:webservicex';
string weather = ws.GetWeather_Http('Paris / Le Bourget', 'France');
System.debug(weather);

Success!

enter image description here

This isn't really Wsdl2Apex anymore as it is using an HttpRequest. It is however calling the SOAP based web service from Salesforce using details stored in a Named Credential.

3
  • Thanks very much for your help with this. I went through the same steps as you and was hoping that I just wasn't retrieving the values from the Named Credential correctly. I will definitely give FuseIT a try. Thanks again for your time on this.
    – Jason
    Commented May 1, 2015 at 15:04
  • I can't seem to get passed the spam-bot validation on the download page for FuseIT SFDC Explorer. Can you PM a download link to me?
    – Jason
    Commented May 1, 2015 at 16:02
  • @Jason I don't think the StackExchange sites provide a PM facility. My profile links to my twitter handle and blog where you could message me directly. From there I can give you the link. I'd also be interested in any spam-bot validation issues you are having. Commented May 3, 2015 at 9:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .