#1  
Old 19th October 2011, 21:56
xc3f59 xc3f59 is offline
Junior Member
 
Join Date: Oct 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
 
Default SOAP/PHP/Exchange (EWS)

Hello all,

I have followed the guide located at http://www.howtoforge.com/talking-soap-with-exchange and it has been very helpful. However I am getting an error that I cannot figure out.

Code:
<?php

class NTLMSoapClient extends SoapClient {
		function __doRequest($request, $location, $action, $version) {
			$headers = array(
				'Method: POST',
				'Connection: Keep-Alive',
				'User-Agent: PHP-SOAP-CURL',
				'Content-Type: text/xml; charset=utf-8',
				'SOAPAction: "'.$action.'"',
			);  
			$this->__last_request_headers = $headers;
			$ch = curl_init($location);
			
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
			curl_setopt($ch, CURLOPT_POST, true );
			curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
			curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
			curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
			curl_setopt($ch, CURLOPT_USERPWD, $this->user.':'.$this->password);
			$response = curl_exec($ch);
			return $response;
		}   
		function __getLastRequestHeaders() {
			return implode("n", $this->__last_request_headers)."n";
		}   
	}

class ExchangeNTLMSoapClient extends NTLMSoapClient {
		protected $user = 'xxxxxx@xxxxxx.com';
		protected $password = 'xxxxxx';
	}
	

class NTLMStream {
	private $path;
	private $mode;
	private $options;
	private $opened_path;
	private $buffer;
	private $pos;

	public function stream_open($path, $mode, $options, $opened_path) {
		echo "[NTLMStream::stream_open] $path , mode=$mode n";
		$this->path = $path;
		$this->mode = $mode;
		$this->options = $options;
		$this->opened_path = $opened_path;
		$this->createBuffer($path);
		return true;
	}

	public function stream_close() {
		echo "[NTLMStream::stream_close] n";
		curl_close($this->ch);
	}

	public function stream_read($count) {
		echo "[NTLMStream::stream_read] $count n";
		if(strlen($this->buffer) == 0) {
			return false;
		}
		$read = substr($this->buffer,$this->pos, $count);
		$this->pos += $count;
		return $read;
	}

	public function stream_write($data) {
		echo "[NTLMStream::stream_write] n";
		if(strlen($this->buffer) == 0) {
			return false;
		}
		return true;
	}

	public function stream_eof() {
		echo "[NTLMStream::stream_eof] ";
		if($this->pos > strlen($this->buffer)) {
			echo "true n";
			return true;
		}
		echo "false n";
		return false;
	}

	/* return the position of the current read pointer */
	public function stream_tell() {
		echo "[NTLMStream::stream_tell] n";
		return $this->pos;
	}

	public function stream_flush() {
		echo "[NTLMStream::stream_flush] n";
		$this->buffer = null;
		$this->pos = null;
	}

	public function stream_stat() {
		echo "[NTLMStream::stream_stat] n";
		$this->createBuffer($this->path);
		$stat = array(
			'size' => strlen($this->buffer),
		);
		return $stat;
	}

	public function url_stat($path, $flags) {
		echo "[NTLMStream::url_stat] n";
		$this->createBuffer($path);
		$stat = array(
			'size' => strlen($this->buffer),
		);
		return $stat;
	}

	/* Create the buffer by requesting the url through cURL */
	private function createBuffer($path) {
		if($this->buffer) {
			return;
		}
		echo "[NTLMStream::createBuffer] create buffer from : $pathn";
		$this->ch = curl_init($path);
		curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, false);
		curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
		curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
		curl_setopt($this->ch, CURLOPT_USERPWD, $this->user.':'.$this->password);
		echo $this->buffer = curl_exec($this->ch);
		echo "[NTLMStream::createBuffer] buffer size : ".strlen($this->buffer)."bytesn";
		$this->pos = 0;
	}
}
	
class ExchangeNTLMStream extends NTLMStream {
	protected $user = 'xxxx@xxxxx.com';
	protected $password = 'xxxxxxx';
}

stream_wrapper_unregister('https');
stream_wrapper_register('https', 'ExchangeNTLMStream') or die("Failed to register protocol");
$wsdl = "Services.wsdl";
$client = new ExchangeNTLMSoapClient($wsdl);

/* Do something with the web service connection */
stream_wrapper_restore('https');

$FindFolder->Traversal = "Shallow";
	$FindFolder->FolderShape->BaseShape = "Default";
	$FindFolder->ParentFolderIds->DistinguishedFolderId->Id = "root";
	$result = $client->FindFolder($FindFolder);
	$folders = $result->ResponseMessages->FindFolderResponseMessage->RootFolder->Folders->Folder;
	foreach($folders as $folder) {
		echo $folder->DisplayName."n";
	}


	
?>
The errors I am getting are:

Code:
Strict Standards: Creating default object from empty value in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\test.php on line 151

Strict Standards: Creating default object from empty value in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\test.php on line 152

Strict Standards: Creating default object from empty value in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\test.php on line 153

Notice: Trying to get property of non-object in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\test.php on line 155

Notice: Trying to get property of non-object in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\test.php on line 155

Notice: Trying to get property of non-object in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\test.php on line 155

Notice: Trying to get property of non-object in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\test.php on line 155

Notice: Trying to get property of non-object in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\test.php on line 155

Warning: Invalid argument supplied for foreach() in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\test.php on line 156
Any ideas? Do I need to declare $FindFolder as an array?

Thanks,
xc3f59
Reply With Quote
Sponsored Links
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP SOAP EWS Calendar permission script dh90 Programming/Scripts 0 12th July 2010 17:40


All times are GMT +2. The time now is 05:22.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.