Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsWindows Server 2003Windows 2000Windows NTSmall Business ServerVirtual ServerExchange ServerIISHost Integration ServerISA ServerSMSWSUSMOMWindows Media ServerSecurityCertification
Related Topics
SQL ServerMS WindowsMS OfficePC HardwareMore Topics ...

Windows Server Forum / Exchange Server / Development / April 2007

Tip: Looking for answers? Try searching our database.

WebDav - Error - Bad Request when Querying Public Folders?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeanine - 18 Apr 2007 10:16 GMT
Hi,

I have had a webdav query working for about 6 months returning appointments
from public folders calendars successfully.  Now it has been reported to me
that the query returns an error of  'bad request'.  I have tried various
ideas to fix the problem and have now gone back to trying to get some basic
MSDN sample code to work - which it doesn't.

I using a very basic query I can access mailbox calendars, folders etc, but
can't access anything under public folders.  

These is the credentials I'm parsing:

MyCredentialCache = New System.Net.CredentialCache
           MyCredentialCache.Add(New System.Uri(strRootURI), "NTLM", New
System.Net.NetworkCredential(strUserName, strPassword, strDomain))

Where strUserName and strPassword are valid administrator accounts which
should have access to everything.  

The strRootURI that I've parsed that work are:
strRootURI = "http://uranus/exchange/jbloggs/calendar"

The strRootURI that don't work are:
strRootURI = "http://uranus/public/Training"
strRootURI = "http://uranus/public"

These URI's all work when pasted into IE.

Does anyone have any suggestions as to how I can fix the problem?  All I can
think is that something has changed in IIS or Exchange - maybe a new SP is
affecting it?

Any suggestions would be most appreciated.

Thanks
Jeanine
Henning Krause [MVP - Exchange] - 18 Apr 2007 11:47 GMT
Hello,

could you post the xml request that you send to the server?

Best regards,
Henning Krause

> Hi,
>
[quoted text clipped - 38 lines]
> Thanks
> Jeanine
Jeanine - 18 Apr 2007 12:14 GMT
Sure, here is the test code I'm using:

Private Sub Test()
       ' Variables
       Dim Request As System.Net.HttpWebRequest
       Dim Response As System.Net.HttpWebResponse
       Dim MyCredentialCache As System.Net.CredentialCache
       Dim strPassword As String
       Dim strDomain As String
       Dim strUserName As String
       Dim strRootURI As String
       Dim strQuery As String
       Dim bytes() As Byte
       Dim RequestStream As System.IO.Stream
       Dim ResponseStream As System.IO.Stream
       Dim ResponseXmlDoc As System.Xml.XmlDocument
       Dim DisplayNameNodes As System.Xml.XmlNodeList

       Try
           ' Initialize variables.
           strUserName = "exchange"
           strPassword = "exchange"
           strDomain = "Fladgate"
           'strRootURI = "http://uranus/public/Fladgate Training - IT"
           'strRootURI = "http://uranus/public"
           strRootURI = "http://uranus/exchange/chumphreys/calendar"

           ' Build the SQL query.
           strQuery = "<?xml version=""1.0""?>" & _
              "<D:searchrequest xmlns:D = ""DAV:"" >" & _
              "<D:sql>SELECT ""DAV:displayname"" FROM """ & strRootURI &
"""" & _
              "WHERE ""DAV:ishidden"" = false AND ""DAV:isfolder"" = false"
& _
              "</D:sql></D:searchrequest>"

           ' Create a new CredentialCache object and fill it with the network
           ' credentials required to access the server.
           MyCredentialCache = New System.Net.CredentialCache
           MyCredentialCache.Add(New System.Uri(strRootURI), _
              "NTLM", _
              New System.Net.NetworkCredential(strUserName, strPassword,
strDomain) _
              )

           ' Create the PUT HttpWebRequest object.
           Request = CType(System.Net.WebRequest.Create(strRootURI), _
           System.Net.HttpWebRequest)

           ' Add the network credentials to the request.
           Request.Credentials = MyCredentialCache

           ' Specify the SEARCH method.
           Request.Method = "SEARCH"

           ' Encode the body using UTF-8.
           bytes = System.Text.Encoding.UTF8.GetBytes(strQuery)

           ' Set the content header length.  This must be
           ' done before writing data to the request stream.
           Request.ContentLength = bytes.Length

           ' Get a reference to the request stream.
           RequestStream = Request.GetRequestStream()

           ' Write the message body to the request stream.
           RequestStream.Write(bytes, 0, bytes.Length)

           ' Close the Stream object to release the connection
           ' for further use.
           RequestStream.Close()

           ' Set the Content Type header.
           Request.ContentType = "text/xml"

           ' Set the Translate header.
           Request.Headers.Add("Translate", "F")

           ' Send the SEARCH method request and get the
           ' response from the server.
           Response = CType(Request.GetResponse(),
System.Net.HttpWebResponse)

           ' Get the XML response stream.
           ResponseStream = Response.GetResponseStream()

           ' Create the XmlDocument object from the XML response stream.
           ResponseXmlDoc = New System.Xml.XmlDocument
           ResponseXmlDoc.Load(ResponseStream)

           ' Build a list of the DAV:href XML nodes, corresponding to the
folders
           ' in the mailbox.  The DAV: namespace is typically assgigned the
a:
           ' prefix in the XML response body.
           DisplayNameNodes =
ResponseXmlDoc.GetElementsByTagName("a:displayname")

           ' Loop through the returned items (if any).
           If DisplayNameNodes.Count > 0 Then

               Console.WriteLine("Non-folder item display names...")
               MsgBox("Non-folder item display names...")

               Dim i As Integer
               For i = 0 To DisplayNameNodes.Count - 1

                   ' Display the non-folder item displayname.
                   Console.WriteLine(DisplayNameNodes(i).InnerText)
               Next

           Else
               Console.WriteLine("No non-folder items found...")
               MsgBox("No non-folder items found...")
           End If

           ' Clean up.
           ResponseStream.Close()
           Response.Close()

       Catch ex As Exception

           ' Catch any exceptions. Any error codes from the
           ' SEARCH method requests on the server will be caught
           ' here, also.
           Console.WriteLine(ex.Message)
           MsgBox(ex.Message)
       End Try
   End Sub

> Hello,
>
[quoted text clipped - 45 lines]
> > Thanks
> > Jeanine
Henning Krause [MVP - Exchange] - 18 Apr 2007 22:09 GMT
Very strange..

the code runs perfectly against my test exchange server (which ist exchange
2003, sp2). No bad request at all...

I have currently no further idea here...

Henning

> Sure, here is the test code I'm using:
>
[quoted text clipped - 184 lines]
>> > Thanks
>> > Jeanine
Jeanine - 19 Apr 2007 09:28 GMT
Hi, thanks for trying it out.  At least that proves its not my code and must
be something on our server.

Jeanine

> Very strange..
>
[quoted text clipped - 193 lines]
> >> > Thanks
> >> > Jeanine
Jeanine - 20 Apr 2007 09:52 GMT
I have tried the code using on an exchange 2000 server and it works
perfectly.  So the problem is when it runs on our exchange 2003 SP 2 server.

Any more suggestions?

Thanks
Jeanine

> Hi, thanks for trying it out.  At least that proves its not my code and must
> be something on our server.
[quoted text clipped - 198 lines]
> > >> > Thanks
> > >> > Jeanine
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.