Scott per your request I thought that this would be an easier place to post the issues that I was having. The tutorial that you posted, Calling Apex Web Services from PHP | Perspectives on Salesforce.com, well I actually was able to get it to work somewhat. The cURL is actually working now.
What I am having a hard time trying to understand is what benefit do you get from this. I actually just started to code in APEX, writing triggers and classes, but I am trying to find better ways to integrate this with other internal systems and code.
In your example, what do you actually get out of using PHP with a web service. Off the top of my head I cannot conceive anything that would be of value.
Maybe if you posted some examples of what exactly you can do or what you have done, that would be great. Not code examples, I will go to your site for that, but just some ideas on what is it that you have done.
Here is the code that I borrowed from your site and actually was able to get it to work
PHP Code:
<?php
ini_set('soap.wsdl_cache_enabled', '0');
ini_set('soap.wsdl_cache_ttl', '0');
require_once ('/users/msimonds/public_html/includes/sandbox_new.inc');
$parsedURL = parse_url($client->getLocation());
//echo '<pre>' . print_r($parsedURL, true) . '</pre>';
define ("_SFDC_SERVER_", substr($parsedURL['host'],0,strpos($parsedURL['host'], '.')));
define ("_WS_NAME_", 'MyWebService');
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_);
// SOAP Client for Web Service
$client1 = new SoapClient(_WS_WSDL_);
$sforce_header = new SoapHeader(_WS_NAMESPACE_, "SessionHeader", array("sessionId" => $client->getSessionId()));
$client1->__setSoapHeaders(array($sforce_header));
// Setup fake data to send into the web service
$prodAmtArray = array();
$prodAmtArray[] = array('productId'=>'01t40000001RiKC','amount'=>100);
$prodAmtArray[] = array('productId'=>'01t40000001RiKD','amount'=>200);
$wrkArray = array(
'contactId'=>'0036000000nVtpT',
'inputs'=>$prodAmtArray
);
// Call the web service
$response = $client1->myMethod($wrkArray);
// Output results to browser
//echo "<p><pre>" . print_r($response, true) . "</pre></p>";
//echo "Contact Id is " . $response->result->contactId;
$ch = curl_init();
$fp = fopen(_WS_WSDL_, "w");
curl_setopt($ch, CURLOPT_URL, _WS_ENDPOINT_);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIE, 'sid='.$client->getSessionId());
setcookie("sid", $client->getSessionId(), 0, "/", ".salesforce.com", 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_exec($ch);
fclose($fp);
curl_close($ch);
?>
it works like a charm, but I do not understand what you are exactly trying to accomplish here
Bookmarks