WebDAV/MSXML2 Question

Archived discussion from Toril-2.
Sarvis
Sojourner
Posts: 6369
Joined: Fri Jan 26, 2001 6:01 am
Location: Buffalo, NY, USA
Contact:

WebDAV/MSXML2 Question

Postby Sarvis » Thu Oct 12, 2006 2:56 pm

On the off chance anyone here knows about .NET and WebDAV, here's a question:

I'm trying to write a windows service which reads some emails from Exchange
Server through WebDAV, using C#.NET 2.0 and MSXML2. 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:

Code: Select all

protected XmlDataDocument GetOldestEmail(string mailbox)
{
    MSXML2.ServerXMLHTTP40 server = new MSXML2.ServerXMLHTTP40();
    server.open("SEARCH", mailbox, false, mUsername, mPassword);
    server.setRequestHeader("Depth", "1");
    server.setRequestHeader("Content-type", "text/xml");
    server.setRequestHeader("Range", "Rows=0-0");

    string select = "<xml>"
        + "<D>"
        + "<D>"
        + "SELECT \"DAV:href\", "
        + "\"urn:schemas:httpmail:subject\", "
        + "\"urn:schemas:httpmail:textdescription\", "
        + "\"urn:schemas:httpmail:htmldescription\", "
        + "\"urn:schemas:httpmail:datereceived\", "
        + "\"urn:schemas:httpmail:from\" "
        + "FROM scope('shallow traversal of \"" + mailbox + "\"')"
        + "WHERE \"DAV:ishidden\"=false "
        + "AND \"DAV:isfolder\"=false "
        + "ORDER BY \"urn:schemas:httpmail:datereceived\""
        + "</D></D>";
    server.send(select);

    XmlDataDocument dataDoc = new XmlDataDocument();
    dataDoc.LoadXml(server.responseText);

    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?
<a href="http://www.code-haven.com">Code Haven</a> - For all your programming needs.

I detest what you write, but I would give my life to make it possible for you to continue to write. - Some Guy Who Paraphrased Voltaire
Grumdikanikus
Sojourner
Posts: 119
Joined: Tue Mar 20, 2001 6:01 am
Location: Calera, Al, USA

Postby Grumdikanikus » Thu Oct 12, 2006 5:50 pm

I don't know much of anything about programming but it kinda sounds like you need to run that service with some sort of authority that has access to all e-mail boxes. It sounds like when the e-mail come thru, you don't have the authority to view the e-mail or do anything to it.

I might be completely off base but that is how simple my mind works at times.

Grummy
Sarvis
Sojourner
Posts: 6369
Joined: Fri Jan 26, 2001 6:01 am
Location: Buffalo, NY, USA
Contact:

Postby Sarvis » Thu Oct 12, 2006 6:14 pm

You're not far off. I've got it working now, finally... but I'm not sure why so I'm almost afraid to touch it and, for instance, clean up the debug strings still in there.

The thing is, all the other services using this technique are running as LocalSystem. I tried yesterday to login with my admin accounts, and got the same problem with one, and a different error with the other. Today I just figured I might as well try agian, and it worked fine.

It just doesn't make sense...
<a href="http://www.code-haven.com">Code Haven</a> - For all your programming needs.

I detest what you write, but I would give my life to make it possible for you to continue to write. - Some Guy Who Paraphrased Voltaire

Return to “General Discussion Archive”

Who is online

Users browsing this forum: No registered users and 16 guests