When we are connecting to sfdc from php using the SOAP API we are receiving an error message: Element {} item is invalid How can i resolve my issuse
ini_set("soap.wsdl_cache_enabled", "0");
ini_set(E_ALL,1);
ini_set('display_errors',1);
// Include the PHP Toolkit
require_once('salesforceAPI/soapclient/SforcePartnerClient.php');
require_once('salesforceAPI/soapclient/SforceHeaderOptions.php');
// Login
define('USER','xxxxx@sfdc.com');
define('PASSWORD', 'yyyyyyyy');
define('SECURITY_KEY', 'zzzzzzzzzzzzzzz');
//echo userName;
//echo password;
//echo securitytoken;
$sfdc = new SforcePartnerClient();
$SoapClient = $sfdc->createConnection('salesforceAPI/partner.wsdl.xml');
$loginResult = false;
try {
// log in with username, password and security token if required
$loginResult = $sfdc->login(USER, PASSWORD . SECURITY_KEY);
} catch (Exception $e) {
global $errors;
$errors = $e->faultstring;
echo "Fatal Login Error <b>" . $errors . "</b>";
die;
}
// Define constants for the web service. We'll use these later
$parsedURL = parse_url($sfdc->getLocation());
define ("_SFDC_SERVER_", substr($parsedURL['host'],0,strpos($parsedURL['host'], '.')));
define ("_WS_NAME_", 'salesforceAPI/Ctest');
define ("_WS_WSDL_", _WS_NAME_ . '.xml');
define ("_WS_ENDPOINT_", 'https://' . _SFDC_SERVER_ . '.salesforce.com/services/wsdl/class/' . _WS_NAME_);
define ("_WS_NAMESPACE_", 'http://soap.sforce.com/schemas/class/' . _WS_NAME_);
$client = new SoapClient(_WS_WSDL_);
$sforce_header = new SoapHeader(_WS_NAMESPACE_, "SessionHeader", array("sessionId" => $sfdc->getSessionId()));
$client->__setSoapHeaders(array($sforce_header));
$method = $client->__getFunctions();
echo _SFDC_SERVER_."<br>";
echo _WS_NAME_."<br>";
echo _WS_WSDL_."<br>";
echo _WS_ENDPOINT_."<br>";
echo _WS_NAMESPACE_."<br>";
//
try {
$wsParams=array('name' =>'hhhi');
// call the web service via post
$client->cInsert($wsParams);
// this is really bad.
} catch (Exception $e) {
global $errors;
$errors = $e->faultstring;
echo "Ooop! Error: <b>" . $errors . "</b>";
die;
}
The web service class in question is:
global class Ctest {
// Request Class
global class RequestClass {
webservice String accName;
//webservice String accNum;
}
// Response
Class global class ResponseClass {
webservice String acName;
}
// webservice
static ResponseClass cInsert(RequestClass req) {
ResponseClass res = new ResponseClass();
Account a = new Account();
a.Name = req.accName;
insert a;
res.acName = a.Name;
return res;
}
}
Best Answer
Is it possibly because in your php class, you are setting up the web service call with
but your request class parameter is called
accName
, when you then try to extract it withIt's been a long time since I worked with PHP.