You need to sign in to do that
Don't have an account?
PHP Apex webservice parameters null
I'm stuck and could use your help. I followed all of the 20 blogs/posts online like this one that explain how to do this but I can't seem to find the issue. I'm trying to build a custom webservice call from php to my salesforce apex webservice. The parameters I'm passing are coming up null on the other side. Any ideas?
APEX Webservice:
global class CreateCustomerPatient
{
webservice static String createCustomerPatient(String testString)
{
return 'ERROR: testString - ' + testString;
}
}
PHP:
function createSalesforcePatient($wsParams)
{
require_once ('../sfdc/SforcePartnerClient.php');
require_once ('../sfdc/SforceHeaderOptions.php');
//LOGIN CODE REMOVED - WORKING CORRECTLY
// setup the SOAP client modify the headers
$parsedURL = parse_url($sfdc->getLocation());
define ("_SFDC_SERVER_", substr($parsedURL['host'],0,strpos($parsedURL['host'], '.')));
define ("_WS_NAME_", "CreateCustomerPatient");
define ("_WS_WSDL_", "../sfdc/" . _WS_NAME_ . ".wsdl.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));
$response = $client->createCustomerPatient($wsParams);
print_r($response);
}
$wsParams = array('testString' => 'test');
createSalesforcePatient($wsParams);
Response:
stdClass Object ( [result] => ERROR: testString - null )
The WSDL was generated from salesforce and placed at the location specified. It seems to be pulling it correctly. Inside the WSDL it contains the following as expected:
<xsd:element name="createCustomerPatient">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="testString" type="xsd:string" nillable="true"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Any ideas as to what I'm doing wrong? Thanks so much for your assistance, I really appreciate this.
Apex (identical to yours):
global class CreateCustomerPatient
{
webservice static String createCustomerPatient(String testString)
{
return 'ERROR: testString - ' + testString;
}
}
PHP - with my login code, and some diagnostics - setting trace when creating the SOAP client, then calling __getLastRequest():
function createSalesforcePatient($wsParams)
{
require_once ('soapclient/SforcePartnerClient.php');
require_once ('soapclient/SforceHeaderOptions.php');
define("SF_SECURITY_TOKEN", getenv("SECURITY_TOKEN"));
define("SF_USERNAME", getenv("USERNAME"));
define("SF_PASSWORD", getenv("PASSWORD"));
$sfdc = new SforcePartnerClient();
$SoapClient = $sfdc->createConnection("soapclient/partner.wsdl.xml");
$loginResult = false;
try {
// log in with username, password and security token if required
$loginResult = $sfdc->login(SF_USERNAME, SF_PASSWORD.SF_SECURITY_TOKEN);
} catch (Exception $e) {
global $errors;
$errors = $e->faultstring;
echo "Fatal Login Error <b>" . $errors . "</b>";
die;
}
$parsedURL = parse_url($sfdc->getLocation());
define ("_SFDC_SERVER_", substr($parsedURL['host'],0,strpos($parsedURL['host'], '.')));
define ("_WS_NAME_", "CreateCustomerPatient");
define ("_WS_WSDL_", "CreateCustomerPatient.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_, array("trace" => 1));
$sforce_header = new SoapHeader(_WS_NAMESPACE_, "SessionHeader", array("sessionId" => $sfdc->getSessionId()));
$client->__setSoapHeaders(array($sforce_header));
$response = $client->createCustomerPatient($wsParams);
print_r($response);
echo "__getLastRequest()\n";
echo $client->__getLastRequest();
echo "\n";
}
$wsParams = array('testString' => 'test');
createSalesforcePatient($wsParams);
Result:
$ php soapservice.php
stdClass Object
(
[result] => ERROR: testString - test
)
__getLastRequest()
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://soap.sforce.com/schemas/class/CreateCustomerPatient"><SOAP-ENV:Header><ns1:SessionHeader><ns1:sessionId>00DE0000000HegH!AREAQKjpY8VEqiQqfnT2Q5CHxC_h1WP6ltq11Go70tw53z.Sme.MXKtB_FzZL9ARvV7B2E_Zb1xFqGvUBblXSJR4e7tRt9w9</ns1:sessionId></ns1:SessionHeader></SOAP-ENV:Header><SOAP-ENV:Body><ns1:createCustomerPatient><ns1:testString>test</ns1:testString></ns1:createCustomerPatient></SOAP-ENV:Body></SOAP-ENV:Envelope>
Reformatted for readability:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://soap.sforce.com/schemas/class/CreateCustomerPatient">
<SOAP-ENV:Header>
<ns1:SessionHeader>
<ns1:sessionId>00DE0000000HegH!AREAQKjpY8VEqiQqfnT2Q5CHxC_h1WP6ltq11Go70tw53z.Sme.MXKtB_FzZL9ARvV7B2E_Zb1xFqGvUBblXSJR4e7tRt9w9</ns1:sessionId>
</ns1:SessionHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:createCustomerPatient>
<ns1:testString>test</ns1:testString>
</ns1:createCustomerPatient>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
See what __getLastRequest() shows for you - it should point the way to the problem.