Tim
Tim

Reputation: 984

Curl, NuSoap, PHP talking to Exchange server authentication error

I have a PHP script which has been using NuSOAP with curl to consume the Exchange web services. I had it working quite well, talking to an slightly older version of exchange as well as Exchange 2010.

Just recently we did an OS upgrade on the server which upgraded a lot of packages. Since then the Exchange code has not worked. It works fine with the older server still, but will not talk to the Exchange 2010 server at all.

The error coming back is 'HTTP Authentication failed.'

I have of course triple checked to make sure the usernames and passwords are correct, and the code hasn't changed, and the servers haven't changed so it seems to be something to do with the server software upgrade.

It seems strange that it still works with the older exchange server though.

It is told not to validate the ssl certificates as they are self signed due to being test machines at the moment, so I don't think it is a cert verification error. I can authenticate and view the web service on the exchange server via the browser so I know that it is still active.

The server is an Ubuntu Server that has just been upgraded to 10.04.4.

This is a bit of the code that was working and still is with the older Exchange server.

    $client = new nusoap_client($webservice_wsdl, true);
$client->setCredentials($exch_user, $exch_pass, 'ntlm');
$client->setUseCURL(true);
$client->useHTTPPersistentConnection();
    $client->setCurlOption(CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
$client->setCurlOption(CURLOPT_USERPWD, $exch_user.':'.$exch_pass);
$client->setCurlOption(CURLOPT_SSL_VERIFYPEER, false);
$client->setCurlOption(CURLOPT_SSL_VERIFYHOST, false);
$client->soap_defencoding = 'UTF-8';

$xml = '<FindItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"';
$xml .= ' xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" Traversal="Shallow">';
$xml .= '   <ItemShape>';
$xml .= '       <t:BaseShape>IdOnly</t:BaseShape>';
$xml .= '       <t:AdditionalProperties>';
$xml .= '           <t:FieldURI FieldURI="message:From"/>';
$xml .= '           <t:FieldURI FieldURI="item:Subject"/>';
$xml .= '           <t:FieldURI FieldURI="message:IsRead"/>';
$xml .= '           <t:FieldURI FieldURI="item:DateTimeReceived"/>';
$xml .= '           <t:FieldURI FieldURI="calendar:Start"/>';
$xml .= '           <t:FieldURI FieldURI="calendar:End"/>';
$xml .= '           <t:FieldURI FieldURI="calendar:Location"/>';
$xml .= '           <t:FieldURI FieldURI="task:Status"/>';
$xml .= '           <t:FieldURI FieldURI="task:DueDate"/>';
$xml .= '       </t:AdditionalProperties>';
$xml .= '   </ItemShape>';
$xml .= '   <IndexedPageItemView Offset="'.$position.'" MaxEntriesReturned="5" BasePoint="Beginning"/>';
$xml .= '   <ParentFolderIds>';
$xml .= '       '.$fxml;
$xml .= '   </ParentFolderIds>';
$xml .= '</FindItem>';

$result = $client->call('FindItem', utf8_encode($xml));

Upvotes: 0

Views: 4768

Answers (2)

Abid Hussain
Abid Hussain

Reputation: 7762

You can get nusoap classes with samples see below url

http://sourceforge.net/projects/nusoap/

Try This

<?php
/*
 *  $Id: wsdlclient3b.php,v 1.1 2004/06/15 15:38:29 snichol Exp $
 *
 *  WSDL client sample.
 *
 *  Service: WSDL
 *  Payload: rpc/encoded (params as an XML string; cf. wsdlclient3.php)
 *  Transport: http
 *  Authentication: none
 */
require_once('../lib/nusoap.php');
$proxyhost = isset($_POST['proxyhost']) ? $_POST['proxyhost'] : '';
$proxyport = isset($_POST['proxyport']) ? $_POST['proxyport'] : '';
$proxyusername = isset($_POST['proxyusername']) ? $_POST['proxyusername'] : '';
$proxypassword = isset($_POST['proxypassword']) ? $_POST['proxypassword'] : '';
$client = new soapclient('http://www.scottnichol.com/samples/hellowsdl2.php?wsdl', true, $proxyhost, $proxyport, $proxyusername, $proxypassword);
$err = $client->getError();
if ($err) {
    echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$params = '<person xsi:type="tns:Person"><firstname xsi:type="xsd:string">Willi</firstname><age xsi:type="xsd:int">22</age><gender xsi:type="xsd:string">male</gender></person>';
$result = $client->call('hello', $params);
// Check for a fault
if ($client->fault) {
    echo '<h2>Fault</h2><pre>';
    print_r($result);
    echo '</pre>';
} else {
    // Check for errors
    $err = $client->getError();
    if ($err) {
        // Display the error
        echo '<h2>Error</h2><pre>' . $err . '</pre>';
    } else {
        // Display the result
        echo '<h2>Result</h2><pre>';
        print_r($result);
        echo '</pre>';
    }
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>

Upvotes: 1

BrendonKoz
BrendonKoz

Reputation: 473

I think I've found the issue - at least with regard to fixing it. At some point in time there must have been an update (either to Windows, or to Unix) that broke the ability for proper communication over NTLM.

My server uses curl version 7.21. I had a Linode that also used 7.21, but since I can play with that, I upgraded the curl (with SSL) to version 7.26 which provides NTLMv2 support (something 7.21 did not). According to the only website that I found to help with this information, apparently version 7.25 also worked: http://blog.ianty.com/ubuntu/exchange-web-services-ews-ntlmv2-and-linux/

I'm replying here as an answer, but I can't definitively say it is in fact the answer. It is one possible answer at least though.

Upvotes: 0

Related Questions