I'm trying to write a windows service which reads some emails from Exchange
Server through WebDAV, using C#.NET 2.0. Everything works fine when testing,
using a little Forms application to test all the backend classes. However,
when I try to run the actual service it gets an access denied message when
trying to get the emails.
We have other services written in VB.NET 1.1 which use the exact same
technique, and run on the same server... and they work fine. So why would it
stop working when run as a .NET 2.0 service?
Here is the function which actually gets the email:
protected XmlDataDocument GetOldestEmail( string mailbox)
{
MSXML2.ServerXM LHTTP40 server = new MSXML2.ServerXM LHTTP40();
server.open("SE ARCH", mailbox, false, mUsername, mPassword);
server.setReque stHeader("Depth ", "1");
server.setReque stHeader("Conte nt-type", "text/xml");
server.setReque stHeader("Range ", "Rows=0-0");
string select = "<?xml version=\"1.0\" ?>"
+ "<D:searchreque st xmlns:D = \"DAV:\">"
+ "<D:sql>"
+ "SELECT \"DAV:href\" , "
+ "\"urn:schemas: httpmail:subjec t\", "
+ "\"urn:schemas: httpmail:textde scription\", "
+
"\"urn:schemas: httpmail:htmlde scription\", "
+ "\"urn:schemas: httpmail:datere ceived\", "
+ "\"urn:schemas: httpmail:from\" "
+ "FROM scope('shallow traversal of \"" + mailbox + "\"')"
+ "WHERE \"DAV:ishidden\ "=false "
+ "AND \"DAV:isfolder\ "=false "
+ "ORDER BY \"urn:schemas:h ttpmail:daterec eived\""
+ "</D:sql></D:searchrequest >";
server.send(sel ect);
XmlDataDocument dataDoc = new XmlDataDocument ();
dataDoc.LoadXml (server.respons eText);
return dataDoc;
}
The mailbox would be something like
https://owa.companyname.com/exchange/dispatch/IMOnsite and the
username/password are definately correct.
Any thoughts on why I'm getting Access Denied?