views:

581

answers:

2

Hi Guys,

I'm creating a window based program to retrieve emails in Exchange Server 2003 using webDAV.

im getting the error on loResponse = (HttpWebResponse)loRequest.GetResponse();

Here's the code:

                lsRootUri = p_strServer + "/Exchange//" + p_strAlias + "//" + p_strInboxURL + "//";


            lsQuery = "<?xml version=\"1.0\"?>"
                        + "<D:searchrequest xmlns:D = \"DAV:\" xmlns:m=\"urn:schemas:httpmail:\">"
                        + "<D:sql>SELECT \"urn:schemas:httpmail:hasattachment\", \"DAV:displayname\", "
                        + "\"urn:schemas:httpmail:from\", \"urn:schemas:httpmail:subject\", "
                        + "\"urn:schemas:httpmail:htmldescription\" FROM \"" + lsRootUri
                        + "\" WHERE \"DAV:ishidden\" = false "
                        + "AND \"DAV:isfolder\" = false " 
                        + "AND \"urn:schemas:httpmail:hasattachment\" = true "
                        + "AND \"urn:schemas:httpmail:read\" = false"
                        + "</D:sql></D:searchrequest>";
            loRequest = (HttpWebRequest)WebRequest.Create(lsRootUri);
            loRequest.Credentials = new NetworkCredential(p_strUserName, p_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();
A: 

There are various things that could be going wrong here:

  • You can't establish a connection to the actual server.
  • You can't establish a connection to the mail server.

I'd check that the network credentials you have are valid and give you the access you need.

Something else that's just sprung to mind is to check that you're trying to connect on the correct port. Connecting interactively will do this as the programs you use will have the ports set up, however in your program you'll need to set the port. The server could be set up to reject connections on the "wrong" ports.

ChrisF
from the laptop that im using i can access the server using outlook and i can also access the server via webmail.do i need to do anything to gain access?
A: 

i remove the domain name from the user name and it is now working...