XML Premature end of data - php

when running the code below I get the following errors:
Failed loading XML Premature end of data in tag Request line 2
Fatal error: Call to a member function asXml() on a non-object in /home4/viptrav3/public_html/wp-content/themes/voyage-child/transfer.php on line 61
Line 61 is $requestFile->asXml('trequest.xml');
But I don't see the premature closing of the XML. I want to save this as a XML file trequest.xml
//Build XML Request
$requestData = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
$requestData .= '<Request>';
// Create Request Header
$requestData .= '<Source>';
// Add Requestor ID data
$requestData .= '<RequestorID Client="' . $clientID . '" EMailAddress="' . $email . '" Password="' . $password . '" />';
// Add Requestor Preferences data
$requestData .= '<RequestorPreferences Language="' . $language . '" Currency="USD" Country="US" >';
$requestData .= '<RequestMode>' . $requestMode . '</RequestMode>';
$requestData .= '</RequestorPreferences>';
$requestData .= '</Source>';
// Create Request Body
$requestData .= '<RequestDetails>
<SearchTransferPriceRequest>
<TransferPickUp>
<PickUpCityCode>LON</PickUpCityCode>
<PickUpCode>A</PickUpCode>
<PickUpPointCode>LCY</PickUpPointCode>
</TransferPickUp>
<TransferDropOff>
<DropOffCityCode>EDI</DropOffCityCode>
<DropOffCode>H</DropOffCode>
</TransferDropOff>
<TransferDate>
2013-11-11</TransferDate>
<NumberOfPassengers>2</NumberOfPassengers>
<PreferredLanguage>E</PreferredLanguage>
</SearchTransferPriceRequest>
</RequestDetails>';
//Save Request & Display XML errors
libxml_use_internal_errors(true);
$sxe = simplexml_load_string($requestData);
if ($sxe === false) {
echo "Failed loading XML\n";
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
}
$requestFile = simplexml_load_string($requestData);
$requestFile->asXml('trequest.xml');

You have to close <Request> tag at the end.
Also it's not good to build XML by hand. Use DOMDocument class instead.

Related

SOAP Error : rg.xml.sax.SAXException: SimpleDeserializer encountered a child element

I have working with SOAP in yii2 and I got an error when I tried to process a soap call
This my soap request :
$xmlInput = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.interfaces.sessions.uams.amdocs\" xmlns:util=\"http://utils.uams.amdocs\" xmlns:web=\"http://webservices.fw.jf.amdocs\"><soapenv:Header/><soapenv:Body><ws:createUser><ws:aCreateUserInfo><util:userId>" . strtoupper($Userid) . "</util:userId><util:effDate>" . $Effdate . "T00:00:09+07:00</util:effDate><util:expDate>" . $Expdate . "T00:00:09+07:00</util:expDate><util:password>" . $this->randomPassword(8) . "</util:password><util:userRoles><ws:item>" . $Role . "</ws:item></util:userRoles></ws:aCreateUserInfo><ws:_awsi_header><web:securedTicket>" . $Ticket . "</web:securedTicket></ws:_awsi_header></ws:createUser></soapenv:Body></soapenv:Envelope>";
Finally I got a response like this :
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Server.userException</faultcode><faultstring>org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.</faultstring><detail><faultData><cause xsi:nil="true"/><exception xsi:nil="true"/><message>SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.</message></faultData><ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">ocsbrntapp4</ns1:hostname></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>
Anybody can help me to fix this issue? Thank you
Try downloading SOAP UI and do a request from there. You will easily be able to see what you are missing.
https://www.soapui.org/downloads/latest-release.html
SOAP UI will automatically tell you exactly what the xml should look like when you post to web service so it is very easy to see where you made a mistake.
Your problem is probably caused by incorrect escaped xml file.
please examine $xmlInput
Based on your code, I would assome that the problem is inside your "$this->randomPassword(8)" function, but without seeing this function I am just asuming.
if you output $xmlInput and see illegal xml characters in there, you can escape them in 2 ways.
1) $xmlInput = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.interfaces.sessions.uams.amdocs\" xmlns:util=\"http://utils.uams.amdocs\" xmlns:web=\"http://webservices.fw.jf.amdocs\"><soapenv:Header/><soapenv:Body><ws:createUser><ws:aCreateUserInfo><util:userId>" . strtoupper($Userid) . "</util:userId><util:effDate>" . $Effdate . "T00:00:09+07:00</util:effDate><util:expDate>" . $Expdate . "T00:00:09+07:00</util:expDate><util:password><![CDATA[" . htmlentities($this->randomPassword(8), ENT_XHTML, 'UTF-8') . "]]></util:password><util:userRoles><ws:item>" . $Role . "</ws:item></util:userRoles></ws:aCreateUserInfo><ws:_awsi_header><web:securedTicket>" . $Ticket . "</web:securedTicket></ws:_awsi_header></ws:createUser></soapenv:Body></soapenv:Envelope>";
2) $xmlInput = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.interfaces.sessions.uams.amdocs\" xmlns:util=\"http://utils.uams.amdocs\" xmlns:web=\"http://webservices.fw.jf.amdocs\"><soapenv:Header/><soapenv:Body><ws:createUser><ws:aCreateUserInfo><util:userId>" . strtoupper($Userid) . "</util:userId><util:effDate>" . $Effdate . "T00:00:09+07:00</util:effDate><util:expDate>" . $Expdate . "T00:00:09+07:00</util:expDate><util:password><![CDATA[" . $this->randomPassword(8) . "]]></util:password><util:userRoles><ws:item>" . $Role . "</ws:item></util:userRoles></ws:aCreateUserInfo><ws:_awsi_header><web:securedTicket>" . $Ticket . "</web:securedTicket></ws:_awsi_header></ws:createUser></soapenv:Body></soapenv:Envelope>";
Basically check the contents of $xmlInput and, make sure that all values are escaped properly.

PHP eBay GetOrders API (Unable To fetch Any Data)

I am Trying to fetch ebay orders by using getOrders API, when i execute ebay PHP SDK it print:
"Sorry No entries found in the Time period requested. Change CreateTimeFrom/CreateTimeTo and Try again"
Please Help me...
Official ebay PHP SDK code :
<?php
/* © 2013 eBay Inc., All Rights Reserved */
/* Licensed under CDDL 1.0 - http://opensource.org/licenses/cddl1.php */
?>
<?php require_once('get-common/keys.php') ; //include keys file for auth token and other credentials ?>
<?php require_once('get-common/eBaySession.php') ; //include session file for curl operations ?>
<?php
//SiteID must also be set in the Request's XML
//SiteID = 0 (US) - UK = 3, Canada = 2, Australia = 15, ....
//SiteID Indicates the eBay site to associate the call with
$siteID = 0;
//the call being made:
$verb = 'GetOrders';
//Time with respect to GMT
//by default retreive orders in last 30 minutes
$CreateTimeFrom = gmdate("Y-m-d\TH:i:s",time()-(2*40*24*60*60)); //current time minus 80 Days
//echo "</br>";
$CreateTimeTo = gmdate("Y-m-d\TH:i:s");
//If you want to hard code From and To timings, Follow the below format in "GMT".
//$CreateTimeFrom = YYYY-MM-DDTHH:MM:SS; //GMT
//$CreateTimeTo = YYYY-MM-DDTHH:MM:SS; //GMT
///Build the request Xml string
$requestXmlBody = '<?xml version="1.0" encoding="utf-8" ?>';
$requestXmlBody .= '<GetOrdersRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
$requestXmlBody .= '<DetailLevel>ReturnAll</DetailLevel>';
$requestXmlBody .= "<CreateTimeFrom>".$CreateTimeFrom."</CreateTimeFrom><CreateTimeTo>".$CreateTimeTo."</CreateTimeTo>";
$requestXmlBody .= '<OrderRole>Seller</OrderRole><OrderStatus>All</OrderStatus>';
$requestXmlBody .= "<RequesterCredentials><eBayAuthToken>$userToken</eBayAuthToken></RequesterCredentials>";
$requestXmlBody.="<WarningLevel>High</WarningLevel>";
$requestXmlBody .= '</GetOrdersRequest>';
//Create a new eBay session with all details pulled in from included keys.php
$session = new eBaySession($userToken, $devID, $appID, $certID, $serverUrl, $compatabilityLevel, $siteID, $verb);
//send the request and get response
$responseXml = $session->sendHttpRequest($requestXmlBody);
if (stristr($responseXml, 'HTTP 404') || $responseXml == '')
die('<P>Error sending request');
//echo "<pre>";
//var_dump($responseXml);
//die;
//Xml string is parsed and creates a DOM Document object
$responseDoc = new DomDocument();
$responseDoc->loadXML($responseXml);
//get any error nodes
$errors = $responseDoc->getElementsByTagName('Errors');
$response = simplexml_import_dom($responseDoc);
$entries = $response->PaginationResult->TotalNumberOfEntries;
//if there are error nodes
if ($errors->length > 0) {
echo '<P><B>eBay returned the following error(s):</B>';
//display each error
//Get error code, ShortMesaage and LongMessage
$code = $errors->item(0)->getElementsByTagName('ErrorCode');
$shortMsg = $errors->item(0)->getElementsByTagName('ShortMessage');
$longMsg = $errors->item(0)->getElementsByTagName('LongMessage');
//Display code and shortmessage
echo '<P>', $code->item(0)->nodeValue, ' : ', str_replace(">", ">", str_replace("<", "<", $shortMsg->item(0)->nodeValue));
//if there is a long message (ie ErrorLevel=1), display it
if (count($longMsg) > 0)
echo '<BR>', str_replace(">", ">", str_replace("<", "<", $longMsg->item(0)->nodeValue));
}else { //If there are no errors, continue
if(isset($_GET['debug']))
{
header("Content-type: text/xml");
print_r($responseXml);
}else
{ //$responseXml is parsed in view.php
include_once 'view.php';
}
}
?>
I would recommend the ebay-sdk-php from devbay.net :
https://github.com/davidtsadler/ebay-sdk-php
https://github.com/davidtsadler/ebay-sdk-examples
As for the date, I could be wrong, but I think it requires DateTime. Something like
CreateTimeFrom = new DateTime('02-10-2016');
CreateTimeTo = new DateTime('02-11-2016');
But I think you will have an easier time with the ebay-sdk-php
edit:
Actually I've been messing around with this more lately.
The default works for me
$CreateTimeFrom = gmdate("Y-m-d\TH:i:s",time()-1800); //current time minus 30 minutes
$CreateTimeTo = gmdate("Y-m-d\TH:i:s");
or you can hardcode your range like the following:
//If you want to hard code From and To timings, Follow the below format in "GMT".
//$CreateTimeFrom = YYYY-MM-DDTHH:MM:SS; //GMT
//$CreateTimeTo = YYYY-MM-DDTHH:MM:SS; //GMT
such as the following:
$CreateTimeFrom = '2017-03-20T00:00:00Z'; //GMT
$CreateTimeTo = '2017-03-22T00:00:00Z'; //GMT
Alternatively, you can just simply not use CreatedTimeTo and CreatedTimeFrom and use NumberOfDays instead
which is basically just commenting out CreatedTimeTo and CreatedTimeFrom
//$requestXmlBody .= "<CreateTimeFrom>$CreateTimeFrom</CreateTimeFrom><CreateTimeTo>$CreateTimeTo</CreateTimeTo>";
and directly underneath it use NumberOfDays
$requestXmlBody .= "<NumberOfDays>2</NumberOfDays>";

How to get eBay item URL based on item ID

I would like to get the item URL based on the item ID. After searching, I found that I can use GetSingleItem to achieve my goal. However, I got an error:
eBay returned the following error(s):
2 : Unsupported API call.
The API call "GetSingleItem" is invalid or not supported in this release.
Here is my code (all configuration are correct because I can use GetOrders by using these configs):
$subverb = "GetSingleItem";
$requestXmlBody = '<?xml version="1.0" encoding="utf-8" ?>';
$requestXmlBody .= '<GetSingleItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
$requestXmlBody .= "<ItemID>111986554711</ItemID>";
$requestXmlBody .= '</GetSingleItemRequest>';
//Create a new eBay session with all details pulled in from included keys.php
$session = new eBaySession($userToken, $devID, $appID, $certID, $serverUrl, $compatabilityLevel, $siteID, $subverb);
//send the request and get response
$responseXml = $session->sendHttpRequest($requestXmlBody);
if (stristr($responseXml, 'HTTP 404') || $responseXml == '')
die('<P>Error sending request');
//Xml string is parsed and creates a DOM Document object
$responseDoc = new DomDocument();
$responseDoc->loadXML($responseXml);
//get any error nodes
$errors = $responseDoc->getElementsByTagName('Errors');
$response = simplexml_import_dom($responseDoc);
$entries = $response->PaginationResult->TotalNumberOfEntries;
//if there are error nodes
if ($errors->length > 0) {
echo '<P><B>eBay returned the following error(s):</B>';
//display each error
//Get error code, ShortMesaage and LongMessage
$code = $errors->item(0)->getElementsByTagName('ErrorCode');
$shortMsg = $errors->item(0)->getElementsByTagName('ShortMessage');
$longMsg = $errors->item(0)->getElementsByTagName('LongMessage');
//Display code and shortmessage
echo '<P>', $code->item(0)->nodeValue, ' : ', str_replace(">", ">", str_replace("<", "<", $shortMsg->item(0)->nodeValue));
//if there is a long message (ie ErrorLevel=1), display it
if (count($longMsg) > 0)
echo '<BR>', str_replace(">", ">", str_replace("<", "<", $longMsg->item(0)->nodeValue));
} else { //If there are no errors, continue
if (isset($_GET['debug'])) {
header("Content-type: text/xml");
print_r($responseXml);
} else {
print("\n; 111986554711: " . $response->Item->ViewItemURLForNaturalSearch);
}
}
Any suggestion? Thank you .
As you discovered, you don't need the API to construct a simple eBay view item landing page URL.
The URL format you discovered works, but it's very old and might not be supported in full or for much longer.
Here's a simple URL format that is pretty current that you can use:
http://www.ebay.com/itm/122225724269
I got an answer without using api. Here is the answer: after I got item ID, I can use "http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=".$item_id to show my product on ebay.
I found this uri by using GetOrders API.
OrderArray.Order .TransactionArray.Transaction .Variation .VariationViewItemURL
Tip: "not optimized for natural search"
If anyone has any idea about "GetSingleItem", I am willing to know why my code doesn't work.

Get all items with all details in XML format

I am trying to get all items using the ebay API in XML format.
See the below code for the same.
require_once('config/ebay_config.php');
require_once('helpers/eBaySession.php');
session_start();
//SiteID must also be set in the Request's XML
//SiteID = 0 (US) - UK = 3, Canada = 2, Australia = 15, ....
//SiteID Indicates the eBay site to associate the call with
$siteID = 0;
//the call being made:
$verb = 'GetSellerList';
///Build the request Xml string
$requestXmlBody = '<?xml version="1.0" encoding="utf-8" ?>';
$requestXmlBody .= '<GetSellerListRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
$requestXmlBody .= '<EndTimeFrom>2015-12-12T11:36:06.487Z</EndTimeFrom>';
$requestXmlBody .= '<EndTimeTo>2016-03-12T11:36:06.487Z</EndTimeTo>';
$requestXmlBody .= '<RequesterCredentials><eBayAuthToken>' . $userToken . '</eBayAuthToken></RequesterCredentials>';
$requestXmlBody .= '<UserID>****</UserID>';
$requestXmlBody .= '<DetailLevel>ItemReturnDescription</DetailLevel>';
$requestXmlBody .= '<Pagination><EntriesPerPage>200</EntriesPerPage><PageNumber>1</PageNumber></Pagination>';
$session = new eBaySession($userToken, $devID, $appID, $certID, $serverUrl, $compatabilityLevel, $siteID, $verb);
//send the request and get response
$responseXml = $session->sendHttpRequest($requestXmlBody);
if (stristr($responseXml, 'HTTP 404') || $responseXml == '')
die('<P>Error sending request');
//Xml string is parsed and creates a DOM Document object
$responseDoc = new DomDocument();
$responseDoc->loadXML($responseXml);
$errors = $responseDoc->getElementsByTagName('Errors');
if ($errors->length > 0) {
echo '<P><B>eBay returned the following error(s):</B>';
//display each error
//Get error code, ShortMesaage and LongMessage
$code = $errors->item(0)->getElementsByTagName('ErrorCode');
$shortMsg = $errors->item(0)->getElementsByTagName('ShortMessage');
$longMsg = $errors->item(0)->getElementsByTagName('LongMessage');
echo '<P>', $code->item(0)->nodeValue, ' : ', str_replace(">", ">", str_replace("<", "<", $shortMsg->item(0)->nodeValue));
echo '<BR/>User Session ID: ' . $_COOKIE["eBaySession"] . '';
if (count($longMsg) > 0)
echo '<BR>', str_replace(">", ">", str_replace("<", "<", $longMsg->item(0)->nodeValue));
}
else { //no errors
//get the nodes needed
$sellerNode = $responseDoc->getElementsByTagName('Seller');
if ($sellerNode->length > 0) {
echo '<P><B>Seller</B>';
$userIDNode = $sellerNode->item(0)->getElementsByTagName('UserID');
$scoreNode = $sellerNode->item(0)->getElementsByTagName('FeedbackScore');
$regDateNode = $sellerNode->item(0)->getElementsByTagName('RegistrationDate');
echo '<BR>UserID: ', $userIDNode->item(0)->nodeValue;
echo '<BR>Feedback Score: ', $scoreNode->item(0)->nodeValue;
echo '<BR>Registration Date: ', $regDateNode->item(0)->nodeValue;
}
}
It just returns seller info, but give advice for the get all items with all details.
And also one more thing, I'm done with login ebay API, and also get a success message on ebay site from below URL but I want to throw on a particular PHP page with userid.
https://signin.ebay.com/ws/eBayISAPI.dll?SignIn&RuName=<?php echo $RuName; ?>&SessID=<?php echo $sessionID; ?>
Presuming that when you say 'All Items' you mean that you want to retrieve all seller listings:
You need to change your DetailLevel node in your initial request to 'ReturnAll'. See the following API page for details. Please note, it is not technically recommended to use the ReturnAll DetailLevel, so you may want to find precisely what you need and only return that level of detail.
eBay GetSellerList
If you are looking for All Items in a category or something (ie not associated with your seller account) you need to use the finding API if I recall correctly.. I originally said advertising but that's not eBay =p

Help with Exchange 2010 EWS (API) and/or PHP's NuSOAP library?

Just to be clear before continuing: using PHP's built-in SOAP class is unfortunately not an option here (production server's PHP is not built with it, and won't be).
I'm trying to use EWS to allow me to authenticate users for a completely external server application. LDAP authentication has been disallowed. I have verified my EWS wsdl is correct via http://www.testexchangeconnectivity.com/, a Microsoft autodiscover tool. The contents of the WSDL can be found here: http://pastebin.org/214070
The server is using SSL, and is using the default authentication method for EWS of "NTLM".
I've tried various code examples around the web, unfortunately I'm not well-versed in XML, SOAP, or cURL (which is pretty much all of the technology being used here). The current iteration of my code is found below:
<?php
include_once('./lib/nusoap.php');
$username = 'username#example.com';
$password = 'password';
$ews_url = 'https://owa.example.com/EWS/Exchange.asmx';
$soapclient = new nusoap_client($service, true);
$soapclient->setCredentials($username, $password, 'ntlm');
$soapclient->setUseCurl(true);
$soapclient->useHTTPPersistentConnection();
$soapclient->setCurlOption(CURLOPT_USERPWD, $username.':'.$password);
$soapclient->soap_defencoding = 'UTF-8';
$params = '<FindItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"';
$params += ' xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" Traversal="Shallow">';
$params += ' <ItemShape>';
$params += ' <t:BaseShape>IdOnly</t:BaseShape>';
$params += ' <t:AdditionalProperties>';
$params += ' <t:FieldURI FieldURI="message:From"/>';
$params += ' <t:FieldURI FieldURI="item:Subject"/>';
$params += ' <t:FieldURI FieldURI="message:IsRead"/>';
$params += ' <t:FieldURI FieldURI="item:DateTimeReceived"/>';
$params += ' <t:FieldURI FieldURI="calendar:Start"/>';
$params += ' <t:FieldURI FieldURI="calendar:End"/>';
$params += ' <t:FieldURI FieldURI="calendar:Location"/>';
$params += ' <t:FieldURI FieldURI="task:Status"/>';
$params += ' <t:FieldURI FieldURI="task:DueDate"/>';
$params += ' </t:AdditionalProperties>';
$params += ' </ItemShape>';
$params += ' <IndexedPageItemView Offset="0" MaxEntriesReturned="5" BasePoint="Beginning"/>';
$params += ' <ParentFolderIds>';
$params += ' <t:DistinguishedFolderId Id="inbox"/>';
$params += ' </ParentFolderIds>';
$params += '</FindItem>';
$operation = 'FindItem';
$namespace = '';
$soapAction = '';
$headers = false;
$result = $soapclient->call($operation, $params, $namespace, $soapAction, $headers);
echo '<pre>'; print_r($result); echo '</pre>';
if($soapclient->fault){
echo 'FAULT: ';
echo '<pre>'; print_r($result); echo '</pre>';
}else{
$err = $soapclient->getError();
if ($err) {
echo '<p><b><u>Error</u>:</b><br />' . $err . '</p>';
}else{
echo 'Connection succeeded.';
}
}
?>
The actual issue I am having is that NuSOAP is returning a generic error message of: "no operations defined in the WSDL document!". From the looks of the WSDL, this seems incorrect and makes me believe I'm missing something in code. If I remove the actual client call in the code ($soapclient->call(...)), the code prints out "Connection succeeded.", but it does this with or without the attempted NTLM authentication code.
I've also tried using the "php-ews" project on my development machine (even though the same code would not work on the production server) and was also unable to access anything without receiving an error.
If anyone has any experience with any of these technologies and might be able to point out some clarification (or possible errors) I would greatly appreciate it. If any further clarification is needed on my part, please let me know.
UPDATE 1:
It seems one error in loading the WSDL is the NTLM Authentication. Using cURL alone (no NuSOAP) I was able to access the WSDL file and find out the server is redirecting to a different endpoint location (.../EWS/Services.wsdl).
Unfortunately, I've tried using the NuSOAP library's cURL ability and setting the same options through NuSOAP, and I am still getting the same generic error message as if NuSOAP is just unable to see/view/access the WSDL file. I believe it may still be NTLM Authentication as the cURL version takes a few moments to return (NTLM it a multi-step handshake process), whereas the NuSOAP client code is immediately returning the error message.
There's a few things you'll want to look at here.
There's an error in your call to the actual soap_client. You defined the endpoint in a variable called $ews_url, but then called the constructor with $service.
Why are you adding a string to a string in your $xml variable - perhaps in your haste you meant to concatenate instead? (operators: + vs .)
Using the following Wiki information directed to working with EWS in Java, it seems that Microsoft has yet again blundered in their implementation of a common protocol. The modification of types.xsd in this Wiki actually causes a problem, so ignore that change, but downloading a local copy of Services.wsdl and modifying it to point to your own server seems to work properly. http://www.bedework.org/trac/bedework/wiki/ExchangeWSlink text
The following code should work, so long as you have downloaded a local copy of your types.xsd, messages.xsd, and Services.wsdl - and modified the Services.wsdl file to add the required information relevant to your server. Make sure the local copies of those files are in the same folder on your server.
<?php
include_once('./lib/nusoap.php');
$username = 'username#example.com';
$password = 'password';
$endpoint = 'http://your.local.version/of/Services.wsdl';
$wsdl = true;
$soapclient = new nusoap_client($endpoint, $wsdl);
$soapclient->setCredentials($username, $password, 'ntlm');
$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="0" MaxEntriesReturned="5" BasePoint="Beginning"/>';
$xml .= ' <ParentFolderIds>';
$xml .= ' <t:DistinguishedFolderId Id="inbox"/>';
$xml .= ' </ParentFolderIds>';
$xml .= '</FindItem>';
$operation = 'FindItem';
$result = $soapclient->call($operation, $xml);
echo '<pre>'; print_r($result); echo '</pre>';
?>
The solution all seems to stem from having a local copy of the main SOAP reference files, and fixing the Services.wsdl file. If you had access to the Exchange server, you might be able to modify the Services.wsdl file and everything could have worked as expected without all of this hassle. I cannot verify this, unfortunately.

Categories