Question

we have a c# application that reads an email Inbox currently hosted on Exchange 2003 using the http service.

Now the mailbox is to be migrated to an Exchange 2010 server, so we are testing our code to confirm it will still work.

We are getting an error 'Bad request' with the below code (which tries to get all the mail): public static XmlDocument GetUnreadMailAll() { HttpWebRequest loRequest = default(HttpWebRequest); HttpWebResponse loResponse = default(HttpWebResponse); string lsRootUri = null; string lsQuery = null; byte[] laBytes = null;

        Stream loRequestStream = default(Stream);
        Stream loResponseStream = default(Stream);
        XmlDocument loXmlDoc = default(XmlDocument);
        loXmlDoc = new XmlDocument();
        try
        {
            lsRootUri = strServer + "/Exchange/" + strAlias + "/" + strInboxURL;
            lsQuery = "<?xml version=\"1.0\"?>"
                + "<D:searchrequest xmlns:D = \"DAV:\" xmlns:m=\"urn:schemas:httpmail:\">"
                + "<D:sql>SELECT "
                + "\"urn:schemas:httpmail:to\", "
                + "\"urn:schemas:httpmail:displayto\", "
                + "\"urn:schemas:httpmail:from\", "
                + "\"urn:schemas:httpmail:fromemail\", "
                + "\"urn:schemas:httpmail:subject\", "
                + "\"urn:schemas:httpmail:textdescription\", "
                //+ "\"urn:schemas:httpmail:htmldescription\", "
                + "\"urn:schemas:httpmail:hasattachment\", "
                + "\"urn:schemas:httpmail:attachmentfilename\", "
                + "\"urn:schemas:httpmail:senderemail\", "
                + "\"urn:schemas:httpmail:sendername\", "
                + "\"DAV:displayname\", "
                + "\"urn:schemas:httpmail:datereceived\", "
                + "\"urn:schemas:httpmail:read\", "
                + "\"DAV:id\" "
                + "FROM \"" + lsRootUri
                + "\" WHERE \"DAV:ishidden\" = false "
                + "AND \"DAV:isfolder\" = false "
                + "AND \"urn:schemas:httpmail:read\" = false "
                + "AND \"urn:schemas:httpmail:fromemail\" != 'emailAddy@domainName.co.uk' "
                + "</D:sql></D:searchrequest>";
            loRequest = (HttpWebRequest)WebRequest.Create(lsRootUri);
            loRequest.Credentials = new NetworkCredential(strUserName, strPassword);
            loRequest.Method = "SEARCH";
            laBytes = System.Text.Encoding.UTF8.GetBytes(lsQuery);
            loRequest.ContentLength = laBytes.Length;
            loRequestStream = loRequest.GetRequestStream();
            loRequestStream.Write(laBytes, 0, laBytes.Length);
            loRequestStream.Close();
            loRequest.ContentType = "text/xml";
            loRequest.Headers.Add("Translate", "F");
            loResponse = (HttpWebResponse)loRequest.GetResponse();
            loResponseStream = loResponse.GetResponseStream();
            loXmlDoc.Load(loResponseStream);
            loResponseStream.Close();
        }

the exception is thrown on the line loResponseStream = loResponse.GetResponseStream();

here is the xml that we are sending:

  <?xml version="1.0" ?> 
- <D:searchrequest xmlns:D="DAV:" xmlns:m="urn:schemas:httpmail:">
  <D:sql>SELECT "urn:schemas:httpmail:to", "urn:schemas:httpmail:displayto", "urn:schemas:httpmail:from", "urn:schemas:httpmail:fromemail", "urn:schemas:httpmail:subject", "urn:schemas:httpmail:textdescription", "urn:schemas:httpmail:hasattachment", "urn:schemas:httpmail:attachmentfilename", "urn:schemas:httpmail:senderemail", "urn:schemas:httpmail:sendername", "DAV:displayname", "urn:schemas:httpmail:datereceived", "urn:schemas:httpmail:read", "DAV:id" FROM "https://domain/Exchange/bbtest/Inbox" WHERE "DAV:ishidden" = false AND "DAV:isfolder" = false AND "urn:schemas:httpmail:read" = false AND "urn:schemas:httpmail:fromemail" != 'emailAddy@domainName.co.uk'</D:sql> 
  </D:searchrequest>
Was it helpful?

Solution

and from MSDN the answer is that WebDAV is deprecated after Exchange 2007, and replaced by Exchange Web Services

here are a couple of links:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top