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
SadminSadmin 

Calling an external Webservice from VisualForce

Hi ,

I am trying to call an external web service from Visual force. I have taken a WSDL from http://strikeiron.com/ .This Web service provides DNS lookup information from a server name. I parsed the WSDL to the apex class and  trying to call the request method in the Converted class from visual force. Visual force page Contains a button .On click ,it should display the dns name of Server passing('www.google.com') But whenever I am clicking on it .Getting an error:-"System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: No user identifier provided faultcode=soap:Client faultactor="



//Generated by wsdl2apex

public class tempuriOrg {
    public class ArrayOfString {
        public String[] string_x;
        private String[] string_x_type_info = new String[]{'string','http://www.w3.org/2001/XMLSchema','string','0','-1','true'};
        private String[] apex_schema_type_info = new String[]{'http://tempuri.org/','true'};
        private String[] field_order_type_info = new String[]{'string_x'};
    }
    public class DNSInfo {
        public String HostName;
        public tempuriOrg.ArrayOfString Aliases;
        public tempuriOrg.ArrayOfString AddressList;
        private String[] HostName_type_info = new String[]{'HostName','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Aliases_type_info = new String[]{'Aliases','http://tempuri.org/','ArrayOfString','0','1','false'};
        private String[] AddressList_type_info = new String[]{'AddressList','http://tempuri.org/','ArrayOfString','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://tempuri.org/','true'};
        private String[] field_order_type_info = new String[]{'HostName','Aliases','AddressList'};
    }
    public class DNSLookupResponse_element {
        public tempuriOrg.DNSInfo DNSLookupResult;
        private String[] DNSLookupResult_type_info = new String[]{'DNSLookupResult','http://tempuri.org/','DNSInfo','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://tempuri.org/','true'};
        private String[] field_order_type_info = new String[]{'DNSLookupResult'};
    }
    public class DNSSoap {
        public String endpoint_x = 'http://ws.strikeiron.com/relauto/iplookup/DNS';
        public wsStrikeironCom.SubscriptionInfo SubscriptionInfo;
        public wsStrikeironCom.LicenseInfo LicenseInfo;
        private String SubscriptionInfo_hns = 'SubscriptionInfo=http://ws.strikeiron.com';
        private String LicenseInfo_hns = 'LicenseInfo=http://ws.strikeiron.com';
        private String[] ns_map_type_info = new String[]{'http://ws.strikeiron.com', 'wsStrikeironCom', 'http://tempuri.org/', 'tempuriOrg'};
        public tempuriOrg.DNSInfo DNSLookup(String server) {
            tempuriOrg.DNSLookup_element request_x = new tempuriOrg.DNSLookup_element();
            tempuriOrg.DNSLookupResponse_element response_x;
            request_x.server = server;
            Map<String, tempuriOrg.DNSLookupResponse_element> response_map_x = new Map<String, tempuriOrg.DNSLookupResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'http://tempuri.org/DNSLookup',
              'http://tempuri.org/',
              'DNSLookup',
              'http://tempuri.org/',
              'DNSLookupResponse',
              'tempuriOrg.DNSLookupResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.DNSLookupResult;
        }
        public void GetRemainingHits() {
            wsStrikeironCom.GetRemainingHits_element request_x = new wsStrikeironCom.GetRemainingHits_element();
            wsStrikeironCom.GetRemainingHitsResponse_element response_x;
            Map<String, wsStrikeironCom.GetRemainingHitsResponse_element> response_map_x = new Map<String, wsStrikeironCom.GetRemainingHitsResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'http://ws.strikeiron.com/relauto/iplookup/DNS/GetRemainingHits',
              'http://ws.strikeiron.com',
              'GetRemainingHits',
              'http://ws.strikeiron.com',
              'GetRemainingHitsResponse',
              'wsStrikeironCom.GetRemainingHitsResponse_element'}
            );
            response_x = response_map_x.get('response_x');
        }
    }
    public class DNSLookup_element {
        public String server;
        private String[] server_type_info = new String[]{'server','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://tempuri.org/','true'};
        private String[] field_order_type_info = new String[]{'server'};
    }
}

It generated one more class wsStrikeironCom inside that I have given the userid and password inside a method called Which is


public class RegisteredUser {
        public String UserID='rachana.raveendran@gmail.com';
        public String Password='*******';
        private String[] UserID_type_info = new String[]{UserID,'http://www.w3.org/2001/XMLSchema','string','0','1','true'};
        private String[] Password_type_info = new String[]{Password,'http://www.w3.org/2001/XMLSchema','string','0','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://ws.strikeiron.com','true'};
        private String[] field_order_type_info = new String[]{UserID,Password};
    }




Here is my visual force code

public class Temperature
{
tempuriOrg.DNSInfo output;
public void recordReplicator()
{
tempuriOrg.DNSSoap stub = new tempuriOrg.DNSSoap(); String nserver='www.google.com'; System.debug('Server Ips'); output= stub.DNSLookup(nserver); System.Debug('output'+output); } public tempuriOrg.DNSInfo getOutput() { return output; } }

Remote site is created for http://ws.strikeiron.com

Please help me to solve this

Thanks


cheenathcheenath
You have to set SubscriptionInfo on the stub before calling web service:


tempuriOrg.DNSSoap stub = new tempuriOrg.DNSSoap();

stub.
SubscriptionInfo = new wsStrikeironCom.SubscriptionInfo();

//set the email, password etc on SubscriptionInfo.
//stub.SubscriptionInfo

Then call the external service method.
SadminSadmin

Thanks for your response.

But i didn’t find any variables in SubscriptionInfo to set the email, password etc on SubscriptionInfo.


This is the generated SubscriptionInfo class

public class SubscriptionInfo {
        public Integer LicenseStatusCode;
        public String LicenseStatus;
        public Integer LicenseActionCode;
        public String LicenseAction;
        public Integer RemainingHits;
        public Double Amount;
        private String[] LicenseStatusCode_type_info = new   String[]{'LicenseStatusCode','http://www.w3.org/2001/XMLSchema','int','1','1','false'};
        private String[] LicenseStatus_type_info = new String[]{'LicenseStatus','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] LicenseActionCode_type_info = new String[]{'LicenseActionCode','http://www.w3.org/2001/XMLSchema','int','1','1','false'};
        private String[] LicenseAction_type_info = new String[]{'LicenseAction','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] RemainingHits_type_info = new String[]{'RemainingHits','http://www.w3.org/2001/XMLSchema','int','1','1','false'};
        private String[] Amount_type_info = new String[]{'Amount','http://www.w3.org/2001/XMLSchema','decimal','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://ws.strikeiron.com','true'};
        private String[] field_order_type_info = new String[]{'LicenseStatusCode','LicenseStatus','LicenseActionCode','LicenseAction','RemainingHits','Amount'};
    }

Can u please suggest a method to set this?

Another class called Registered user is there
    public class RegisteredUser {
        public String UserID='rachana.raveendran@gmail.com';
        public String Password='***********';
        private String[] UserID_type_info = new String[]{UserID,'http://www.w3.org/2001/XMLSchema','string','0','1','true'};
        private String[] Password_type_info = new String[]{Password,'http://www.w3.org/2001/XMLSchema','string','0','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://ws.strikeiron.com','true'};
        private String[] field_order_type_info = new String[]{UserID,Password};
    }
Here i have given the email(userid) and password.
cheenathcheenath
If you dont have subscription, you could set the LicenseInfo :

tempuriOrg.DNSSoap stub = new tempuriOrg.DNSSoap();

stub.
LicenseInfo = new wsStrikeironCom.LicenseInfo();

stub.LicenseInfo.RegisteredUser = new
wsStrikeironCom.RegisteredUser();
stub.LicenseInfo.RegisteredUser.UserId = 'your user id';
stub.LicenseInfo.RegisteredUser.Password = 'your password';

//stub.DNSLookup



SadminSadmin
Hi Cheenath,

I changed the visual force code like this

public class Temperature123
{
tempuriOrg.DNSInfo output;
public pagereference recordReplicator()  

 tempuriOrg.DNSSoap stub = new tempuriOrg.DNSSoap();
 stub.LicenseInfo = new  wsStrikeironCom.LicenseInfo();
stub.LicenseInfo.RegisteredUser = new wsStrikeironCom.RegisteredUser();
stub.LicenseInfo.RegisteredUser.UserID ='rachana.raveendran@gmail.com';
stub.LicenseInfo.RegisteredUser.Password ='**********';
String nserver='www.google.com';
System.debug('Server Ips');
output= stub.DNSLookup(nserver);
System.Debug('output'+output); 
   
 return page.first_visual_force_page;
}  
public tempuriOrg.DNSInfo getoutput()
{
return output;
}

}
But now i am getting an error like

System.CalloutException: Web service callout failed: Unable to find field 'null' found in fieldOrder
silverbulletsilverbullet
First, if you want to see working code within Salesforce that uses StrikeIron Web services (or any Web service), download the StrikeIron AppWidget that contains working source.

Sourcecode:

If you download this from the AppExchange:  http://www.salesforce.com/appexchange/detail_overview.jsp?NavCode__c=&id=a0330000004ZjewAAC

it's free to download and try, and it has the source code available for consuming StrikeIron Web services within Apex. That might help you here. The code would probably be the same for consuming other Web services as well, and the download is a complete certified add-on that enables demographic data to be consumed as a Web service, and then added to a contact record so you have better information to sell with. The code is there and it works.

If you register with StrikeIron you will get 25 free trial hits for every Web service - so register at the site before you try to run any code (it's free). They also provide two sets of WSDLs for each Web service, one that utilizes SOAP Headers, one that doesn't. SOAP Headers are the best way to keep data payloads separate, however they can be more difficult to implement.

If you want to bypass any services that require passwords and just get a few of them running, they also have several free Web services that don't require any authentication:

http://www.strikeiron.com/Marketplace/liteservices.aspx
SFRichSFRich

The AppExchange URL mentioned in this thread for the StrikeIron example is no longer valid.  Can anyone recommend another cdoe example for calling a web service?