-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCrmExecuteSoap.php
43 lines (39 loc) · 1.42 KB
/
CrmExecuteSoap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
class CrmExecuteSoap {
/**
* Executes the SOAP request.
* @return String SOAP response.
* @param CrmAuthenticationHeader $authHeader
* The authenticated CrmAuthenticationHeader.
* @param String $request
* The SOAP request body.
* @param String $url
* The CRM URL.
*/
public function ExecuteSOAPRequest($authHeader, $request, $url) {
$url = rtrim ( $url, "/" );
$xml = "<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:a=\"http://www.w3.org/2005/08/addressing\">";
$xml .= $authHeader->Header;
$xml .= $request;
$xml .= "</s:Envelope>";
$headers = array (
"POST " . "/Organization.svc" . " HTTP/1.1",
"Host: " . str_replace ( "https://", "", $url ),
'Connection: Keep-Alive',
"Content-type: application/soap+xml; charset=UTF-8",
"Content-length: " . strlen ( $xml )
);
$cURL = curl_init ();
curl_setopt ( $cURL, CURLOPT_URL, $url . "/XRMServices/2011/Organization.svc" );
curl_setopt ( $cURL, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $cURL, CURLOPT_TIMEOUT, 60 );
curl_setopt ( $cURL, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt ( $cURL, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 );
curl_setopt ( $cURL, CURLOPT_HTTPHEADER, $headers );
curl_setopt ( $cURL, CURLOPT_POST, 1 );
curl_setopt ( $cURL, CURLOPT_POSTFIELDS, $xml );
$response = curl_exec ( $cURL );
curl_close ( $cURL );
return $response;
}
}