????? ????? ?? ??????? ??? ???? ??????? Exchange Server ???????? HttpWebRequest ?? Visual Basic .NET

?????? ????????? ?????? ?????????
???? ???????: 314191 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

????? ???

????? ??? ??????? ??? ????? ???????? ???????? ???? ????? ?????? ??????? ??? ???? ??????? ???? ????? ??????? Microsoft Exchange 2000 Server:
  • ????? ???? ????
  • ????? ?? ???????
  • ??? ???? ????????
??????? ????? ???????? ???????? HttpWebRequest ????? ? ????? HttpWebResponse ?? ????? ????? System.Net.

??????? ????

???????? HttpWebRequest ????? ??? ??? HttpWebResponse ????? ?? ??????? ?? Exchange 2000 Server:
  1. ??? ????? Microsoft Visual Studio .NET.
  2. ?? ??????? ???? ??? ??? ???? ?? ???? ??? ???????.
  3. ??? ????? Project ? ???? ??? ?????? Visual Basic.
  4. ??? ????? ? ???? ??? ????? ???? ?????? ?? ???? ??? ?????.

    ?????????? ??? ????? Module1.vb.
  5. ?? ???? ????????? ???????? ??????? ????????? ???????? ???????? ??? ????? ???????? ???????? ?? ??? ???????.
  6. ????? ?? "TODO" ?? ????????? ???????? ?? ?? ?????? ????????? ???????? ?????? ?????? ??.
  7. ???? F5 ?????? ? ?????? ????????.

????? ???? ????

????? ???? ???? ?? ?????? ??????? HttpWebRequest.Method "PROPPATCH" ????? ????? ??? ???? ????????? ?????? ???? Exchange Server ?? ?? ???????? ??? HttpWebResponse ???? ?????????.
Imports System.Net
Imports System.IO

Module Module1
    Sub Main()
        ' TODO: Replace the following URL with the URL to the new Appointment item. 
        Dim sUri As String = "http://ExchServer/Exchange/Administrator/Calendar/Test.eml"

        Dim myUri As System.Uri = New System.Uri(sUri)
        Dim HttpWRequest As HttpWebRequest = WebRequest.Create(myUri)

        Dim strXMLNSInfo As String = "xmlns:g=""DAV:"" " & _
         " xmlns:e=""http://schemas.microsoft.com/exchange/""" & _
         " xmlns:mapi=""http://schemas.microsoft.com/mapi/""" & _
         " xmlns:x=""xml:"" xmlns:cal=""urn:schemas:calendar:""" & _
         " xmlns:dt=""urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/""" & _
         " xmlns:mail=""urn:schemas:httpmail:"">"

        Dim sQuery As String = "<?xml version=""1.0""?>" & _
         "<g:propertyupdate " & strXMLNSInfo & _
         "<g:set>" & _
         "<g:prop>" & _
         "<g:contentclass>urn:content-classes:appointment</g:contentclass>" & _
         "<e:outlookmessageclass>IPM.Appointment</e:outlookmessageclass>" & _
         "<mail:subject>Appointment Subject</mail:subject>" & _
         "<cal:location>Appointment Location</cal:location>" & _
         "<cal:dtstart dt:dt=""dateTime.tz"">2002-01-07T22:00:00.000Z</cal:dtstart>" & _
         "<cal:dtend dt:dt=""dateTime.tz"">2002-01-07T22:30:00.000Z</cal:dtend>" & _
         "<cal:instancetype dt:dt=""int"">0</cal:instancetype>" & _
         "<cal:busystatus>BUSY</cal:busystatus>" & _
         "<cal:meetingstatus>TENTATIVE</cal:meetingstatus>" & _
         "<cal:alldayevent dt:dt=""boolean"">0</cal:alldayevent>" & _
         "</g:prop>" & _
         "</g:set>" & _
         "</g:propertyupdate>"

        ' Set credentials.
        ' TODO: Replace the following with appropriate user credentials.
        Dim myCred As NetworkCredential = New NetworkCredential("Domain\UserName", "Password")
        Dim MyCredentialCache As CredentialCache = New CredentialCache()
        MyCredentialCache.Add(myUri, "Basic", myCred)
        HttpWRequest.Credentials = MyCredentialCache

        ' Set headers.
        HttpWRequest.KeepAlive = False
        HttpWRequest.Headers.Set("Pragma", "no-cache")
        HttpWRequest.Headers.Set("Translate", "f")
        HttpWRequest.ContentType = "text/xml"
        HttpWRequest.ContentLength = sQuery.Length

        'Set the request timeout to 5 minutes.
        HttpWRequest.Timeout = 300000
        ' set the request method
        HttpWRequest.Method = "PROPPATCH"

        ' Store the data in a byte array.
        Dim ByteQuery() As Byte = System.Text.Encoding.ASCII.GetBytes(sQuery)
        HttpWRequest.ContentLength = ByteQuery.Length
        Dim QueryStream As Stream = HttpWRequest.GetRequestStream()
        ' Write the data to be posted to the Request stream.
        QueryStream.Write(ByteQuery, 0, ByteQuery.Length)
        QueryStream.Close()

        ' Send the request and get a response.
        Dim HttpWResponse As HttpWebResponse = HttpWRequest.GetResponse()

        ' Get the status and the headers.
        Dim iStatCode As Integer = HttpWResponse.StatusCode
        Dim sStatus As String = iStatCode.ToString()
        Console.WriteLine("Status: {0} {1}", sStatus, HttpWResponse.StatusDescription.ToString())

        Console.WriteLine("Request Headers:")
        Console.WriteLine(HttpWRequest.Headers.ToString())
        Console.WriteLine("Response Headers:")
        Console.WriteLine(HttpWResponse.Headers.ToString())

        ' Get the Response stream.
        Dim strm As Stream = HttpWResponse.GetResponseStream()

        ' Read the Response stream.
        Dim sr As StreamReader = New StreamReader(strm)
        Dim sText As String = sr.ReadToEnd()
        Console.WriteLine("Response: {0}", sText)

        ' Close the stream.
        strm.Close()

        ' Clean up.
        HttpWRequest = Nothing
        HttpWResponse = Nothing
        MyCredentialCache = Nothing
        myCred = Nothing
        strm = Nothing
        sr = Nothing
    End Sub
End Module

????? ?? ???????

????? ?? ????? ????? ??????? HttpWebRequest.Method ??? "SEARCH ?" ????? ????????? ????? ??? ???? Exchange ?? ??? ?? ?? ???????? ??? HttpWebResponse ???? ?????????. ???? ????? ????????? SQL ????????.
Imports System.Net
Imports System.IO

Module Module1
    Sub Main()
        ' TODO: Replace the following URL with the URL of an object on the Exchange Server computer.
        Dim sUri As String = "http://ExchServer/Exchange/Administrator/Inbox/"

        Dim myUri As System.Uri = New System.Uri(sUri)
        Dim HttpWRequest As HttpWebRequest = WebRequest.Create(myUri)

        ' TODO: Search for items whose subject is Test.
        Dim sQuery As String
        sQuery = "<?xml version='1.0'?>" & _
         "<g:searchrequest xmlns:g='DAV:' >" & _
         "<g:sql>SELECT ""DAV:displayname"", " & _
         """DAV:href"" " & _
         "FROM SCOPE('SHALLOW TRAVERSAL OF """ & sUri & """')" & _
         "WHERE ""urn:schemas:mailheader:subject"" = 'Test'" & _
         "</g:sql>" & _
         "</g:searchrequest>"

        ' Set credentials.
        ' TODO: Replace the following with appropriate user credentials.
        Dim myCred As NetworkCredential = New NetworkCredential("Domain\UserName", "Password")
        Dim MyCredentialCache As CredentialCache = New CredentialCache()
        MyCredentialCache.Add(myUri, "Basic", myCred)
        HttpWRequest.Credentials = MyCredentialCache

        ' Set some headers.
        HttpWRequest.KeepAlive = False
        HttpWRequest.Headers.Set("Pragma", "no-cache")

        HttpWRequest.Headers.Set("Translate", "f")
        HttpWRequest.Headers.Set("Depth", "0")
        HttpWRequest.ContentType = "text/xml"
        HttpWRequest.ContentLength = sQuery.Length

        'Set the request timeout to 5 minutes.
        HttpWRequest.Timeout = 300000
        ' set the request method
        HttpWRequest.Method = "SEARCH"

        ' Store the data in a byte array.
        Dim ByteQuery() As Byte = System.Text.Encoding.ASCII.GetBytes(sQuery)
        HttpWRequest.ContentLength = ByteQuery.Length
        Dim QueryStream As Stream = HttpWRequest.GetRequestStream()
        ' write the data to be posted to the Request Stream
        QueryStream.Write(ByteQuery, 0, ByteQuery.Length)
        QueryStream.Close()

        ' Send the request and get a response.
        Dim HttpWResponse As HttpWebResponse = HttpWRequest.GetResponse()

        ' Get the status and the headers.
        Dim iStatCode As Integer = HttpWResponse.StatusCode
        Dim sStatus As String = iStatCode.ToString()
        Console.WriteLine("Status: {0} {1}", sStatus, HttpWResponse.StatusDescription.ToString())

        Console.WriteLine("Request Headers:")
        Console.WriteLine(HttpWRequest.Headers.ToString())
        Console.WriteLine("Response Headers:")
        Console.WriteLine(HttpWResponse.Headers.ToString())

        ' Get the Response stream.
        Dim strm As Stream = HttpWResponse.GetResponseStream()

        ' Read the Response stream.
        Dim sr As StreamReader = New StreamReader(strm)
        Dim sText As String = sr.ReadToEnd()
        Console.WriteLine("Response: {0}", sText)

        ' Close the stream.
        strm.Close()

        ' Clean up.
        HttpWRequest = Nothing
        HttpWResponse = Nothing
        MyCredentialCache = Nothing
        myCred = Nothing
        QueryStream = Nothing
        strm = Nothing
        sr = Nothing
    End Sub
End Module

??? ???? ????????

???? ?? ??? ?????? ????? ???? HttpWebRequest ???????? ??? ???? ???? ????? ?????? (URI) ? ?? ?????? ??????? HttpWebRequest.Method "???" ?? "???" ? ?? URI ?????? ?? ??? ????? ?? ?? ????? ????? ??? ???? ????????? ?????? ???? Exchange Server. ?????? ??? HttpWebResponse ???? ?????????.
Imports System.Net
Imports System.IO

Module Module1

    Sub Main()
        ' TODO: Replace the following with True for MOVE, or False for COPY.
        Dim bMove As Boolean = True

        ' TODO: Replace the following with the source URL. 
        Dim sSourceURL As String = "http://ExchServer/Public/Folder1/Test.EML"

        ' TODO: Replace the following with the destination URL.
        Dim sDestinationURL As String = "http://ExchServer/Public/Folder2/Test.EML"


        Dim myUri As System.Uri = New System.Uri(sSourceURL)
        Dim HttpWRequest As HttpWebRequest = WebRequest.Create(myUri)

        ' Set the credentials.
        ' TODO: Replace the following with appropriate user credentials.
        Dim myCred As NetworkCredential = New NetworkCredential("Domain\UserName", "Password")
        Dim MyCredentialCache As CredentialCache = New CredentialCache()
        MyCredentialCache.Add(myUri, "Basic", myCred)
        HttpWRequest.Credentials = MyCredentialCache

        ' Set headers.
        HttpWRequest.KeepAlive = False
        HttpWRequest.Headers.Set("Pragma", "no-cache")
        HttpWRequest.Headers.Set("Destination", sDestinationURL)

        'Set the request timeout to 5 minutes.
        HttpWRequest.Timeout = 300000
        ' Set the Request method.
        If bMove Then
            HttpWRequest.Method = "MOVE"
        Else
            HttpWRequest.Method = "COPY"
        End If

        ' Send the request and get the response.
        Dim HttpWResponse As HttpWebResponse = HttpWRequest.GetResponse()

        ' Get the status and the headers.
        Dim iStatCode As Integer = HttpWResponse.StatusCode
        Dim sStatus As String = iStatCode.ToString()
        Console.WriteLine("Status: {0} {1}", sStatus, HttpWResponse.StatusDescription.ToString())

        Console.WriteLine("Request Headers:")
        Console.WriteLine(HttpWRequest.Headers.ToString())
        Console.WriteLine("Response Headers:")
        Console.WriteLine(HttpWResponse.Headers.ToString())

        ' Get the Response stream.
        Dim strm As Stream = HttpWResponse.GetResponseStream()

        ' Read the Response stream.
        Dim sr As StreamReader = New StreamReader(strm)
        Dim sText As String = sr.ReadToEnd()
        Console.WriteLine("Response: {0}", sText)

        ' Close the stream.
        strm.Close()

        ' Clean up.
        HttpWRequest = Nothing
        HttpWResponse = Nothing
        MyCredentialCache = Nothing
        myCred = Nothing
        strm = Nothing
        sr = Nothing
    End Sub
End Module

???????

???? ???????: 314191 - ????? ??? ??????: 03/????? ??????/1426 - ??????: 2.2
????? ???
  • Microsoft Exchange 2000 Server Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft XML Parser 3.0
  • Microsoft XML Core Services 4.0
????? ??????: 
kbmt kbhowtomaster kbhowto KB314191 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????314191

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com