|
|
|
date: 30 Jan 2006 04:44:26 -0800,
group: microsoft.public.exchange2000.development
back
Error 403 creating appointment (WebDAV)
Hi All,
I've used the code in this MSDN article:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_esdk_creating_an_appointment_webdav.asp
in my program, but I always receive "The remote server returned an
error: (403) Forbidden" error. This is the complete code:
Private Sub CreateAppointment()
' Variables
Dim strExchSvrName As String
Dim strMailbox As String
Dim strCalendarUri As String
Dim strApptItem As String
Dim strDomain As String
Dim strUserName As String
Dim strPassword As String
Dim strApptRequest As String
Dim strMailInfo As String
Dim strCalInfo As String
Dim strXMLNSInfo As String
Dim strHeaderInfo As String
Dim PROPPATCHRequest As System.Net.HttpWebRequest
Dim PROPPATCHResponse As System.Net.WebResponse
Dim MyCredentialCache As System.Net.CredentialCache
Dim bytes() As Byte
Dim PROPPATCHRequestStream As System.IO.Stream
Try
strExchSvrName = "myserver"
strMailbox = "mymailbox"
strUserName = "myuserid"
strDomain = "mydomain"
strPassword = "mypassword"
strApptItem = "testappointment.eml"
strCalendarUri = "http://" & strExchSvrName & "/exchange/" & _
strMailbox & "/Calendar/"
' XML namespace info for the WebDAV request.
strXMLNSInfo = "xmlns:g=""DAV:"" " & _
"xmlns:e=""http://schemas.microsoft.com/exchange/"" " & _
"xmlns:mapi=""http://schemas.microsoft.com/mapi/"" " & _
"xmlns:mapit=""http://schemas.microsoft.com/mapi/proptag/"" "
& _
"xmlns:x=""xml:"" xmlns:cal=""urn:schemas:calendar:"" " & _
"xmlns:dt=""urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"" "
& _
"xmlns:header=""urn:schemas:mailheader:"" " & _
"xmlns:mail=""urn:schemas:httpmail:"""
' Set the appointment item properties. The reminder time is set
in seconds.
' To create an all-day meeting, set the dtstart/dtend range for
24 hours
' or more and set the alldayevent property to 1. See the
documentation
' on the properties in the urn:schemas:calendar: namespace for
more information.
strCalInfo = "<cal:location>meetappt Location</cal:location>" & _
"<cal:dtstart
dt:dt=""dateTime.tz"">2006-01-30T16:00:00.000Z</cal:dtstart>" & _
"<cal:dtend
dt:dt=""dateTime.tz"">2006-01-30T16:30:00.000Z</cal:dtend>" & _
"<cal:instancetype dt:dt=""int"">0</cal:instancetype>" & _
"<cal:busystatus>BUSY</cal:busystatus>" & _
"<cal:meetingstatus>CONFIRMED</cal:meetingstatus>" & _
"<cal:alldayevent dt:dt=""boolean"">0</cal:alldayevent>" & _
"<cal:responserequested
dt:dt=""boolean"">1</cal:responserequested>" & _
"<cal:reminderoffset dt:dt=""int"">900</cal:reminderoffset>"
' Set the required attendee of the appointment.
strHeaderInfo = "<header:to>" & strMailbox & "</header:to>"
' Set the subject of the appointment.
strMailInfo = "<mail:subject>Test Appointment
Subject</mail:subject>" & _
"<mail:htmldescription>Let's meet
here</mail:htmldescription>"
' Build the XML body of the PROPPATCH request.
strApptRequest = "<?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>" & _
strMailInfo & _
strCalInfo & _
strHeaderInfo & _
"<mapi:finvited dt:dt=""boolean"">1</mapi:finvited>" & _
"</g:prop></g:set>" & _
"</g:propertyupdate>"
' 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(strCalendarUri), "Basic", _
New NetworkCredential(strUserName,
strPassword, strDomain))
' Create the HttpWebRequest object.
PROPPATCHRequest =
CType(System.Net.HttpWebRequest.Create(strCalendarUri & strApptItem), _
System.Net.HttpWebRequest)
' Add the network credentials to the request.
PROPPATCHRequest.Credentials = MyCredentialCache
' Specify the PROPPATCH method.
PROPPATCHRequest.Method = "PROPPATCH"
' Set the content type header.
PROPPATCHRequest.ContentType = "text/xml"
' Encode the body using UTF-8.
bytes = System.Text.Encoding.UTF8.GetBytes(strApptRequest)
' Set the content header length. This must be
' done before writing data to the request stream.
PROPPATCHRequest.ContentLength = bytes.Length
' Get a reference to the request stream.
PROPPATCHRequestStream = PROPPATCHRequest.GetRequestStream()
' Write the message body to the request stream.
PROPPATCHRequestStream.Write(bytes, 0, bytes.Length)
' Close the Stream object to release the connection
' for further use.
PROPPATCHRequestStream.Close()
' Create the appointment in the Calendar folder of the
' user's mailbox.
PROPPATCHResponse = CType(PROPPATCHRequest.GetResponse(),
HttpWebResponse) ' The remote server returned an error: (403)
Forbidden
MessageBox.Show("Appointment successfully created.")
' Clean up.
PROPPATCHResponse.Close()
Catch ex As Exception
' Catch any exceptions. Any error codes from the PROPPATCH
' or MOVE method requests on the server will be caught
' here, also.
MessageBox.Show(ex.Message)
End Try
End Sub
TIA
date: 30 Jan 2006 04:44:26 -0800
author: unknown
Re: Error 403 creating appointment (WebDAV)
Are you sure that appointment or any other item with same URL does not exists?
Michael
-------------------------------
If you need WebDAV API for Exchange server,
use our component WebDAV .NET for Exchange.
Check out http://www.independentsoft.com
wrote in message news:1138625066.816997.80570@g43g2000cwa.googlegroups.com...
> Hi All,
>
> I've used the code in this MSDN article:
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_esdk_creating_an_appointment_webdav.asp
> in my program, but I always receive "The remote server returned an
> error: (403) Forbidden" error. This is the complete code:
>
> Private Sub CreateAppointment()
> ' Variables
> Dim strExchSvrName As String
> Dim strMailbox As String
> Dim strCalendarUri As String
> Dim strApptItem As String
> Dim strDomain As String
> Dim strUserName As String
> Dim strPassword As String
> Dim strApptRequest As String
> Dim strMailInfo As String
> Dim strCalInfo As String
> Dim strXMLNSInfo As String
> Dim strHeaderInfo As String
> Dim PROPPATCHRequest As System.Net.HttpWebRequest
> Dim PROPPATCHResponse As System.Net.WebResponse
> Dim MyCredentialCache As System.Net.CredentialCache
> Dim bytes() As Byte
> Dim PROPPATCHRequestStream As System.IO.Stream
>
> Try
> strExchSvrName = "myserver"
> strMailbox = "mymailbox"
> strUserName = "myuserid"
> strDomain = "mydomain"
> strPassword = "mypassword"
>
> strApptItem = "testappointment.eml"
>
> strCalendarUri = "http://" & strExchSvrName & "/exchange/" & _
> strMailbox & "/Calendar/"
>
> ' XML namespace info for the WebDAV request.
> strXMLNSInfo = "xmlns:g=""DAV:"" " & _
> "xmlns:e=""http://schemas.microsoft.com/exchange/"" " & _
> "xmlns:mapi=""http://schemas.microsoft.com/mapi/"" " & _
> "xmlns:mapit=""http://schemas.microsoft.com/mapi/proptag/"" "
> & _
> "xmlns:x=""xml:"" xmlns:cal=""urn:schemas:calendar:"" " & _
> "xmlns:dt=""urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"" "
> & _
> "xmlns:header=""urn:schemas:mailheader:"" " & _
> "xmlns:mail=""urn:schemas:httpmail:"""
>
> ' Set the appointment item properties. The reminder time is set
> in seconds.
> ' To create an all-day meeting, set the dtstart/dtend range for
> 24 hours
> ' or more and set the alldayevent property to 1. See the
> documentation
> ' on the properties in the urn:schemas:calendar: namespace for
> more information.
> strCalInfo = "<cal:location>meetappt Location</cal:location>" & _
> "<cal:dtstart
> dt:dt=""dateTime.tz"">2006-01-30T16:00:00.000Z</cal:dtstart>" & _
> "<cal:dtend
> dt:dt=""dateTime.tz"">2006-01-30T16:30:00.000Z</cal:dtend>" & _
> "<cal:instancetype dt:dt=""int"">0</cal:instancetype>" & _
> "<cal:busystatus>BUSY</cal:busystatus>" & _
> "<cal:meetingstatus>CONFIRMED</cal:meetingstatus>" & _
> "<cal:alldayevent dt:dt=""boolean"">0</cal:alldayevent>" & _
> "<cal:responserequested
> dt:dt=""boolean"">1</cal:responserequested>" & _
> "<cal:reminderoffset dt:dt=""int"">900</cal:reminderoffset>"
>
> ' Set the required attendee of the appointment.
> strHeaderInfo = "<header:to>" & strMailbox & "</header:to>"
>
> ' Set the subject of the appointment.
> strMailInfo = "<mail:subject>Test Appointment
> Subject</mail:subject>" & _
> "<mail:htmldescription>Let's meet
> here</mail:htmldescription>"
>
> ' Build the XML body of the PROPPATCH request.
> strApptRequest = "<?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>" & _
> strMailInfo & _
> strCalInfo & _
> strHeaderInfo & _
> "<mapi:finvited dt:dt=""boolean"">1</mapi:finvited>" & _
> "</g:prop></g:set>" & _
> "</g:propertyupdate>"
>
> ' 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(strCalendarUri), "Basic", _
> New NetworkCredential(strUserName,
> strPassword, strDomain))
>
> ' Create the HttpWebRequest object.
> PROPPATCHRequest =
> CType(System.Net.HttpWebRequest.Create(strCalendarUri & strApptItem), _
> System.Net.HttpWebRequest)
>
> ' Add the network credentials to the request.
> PROPPATCHRequest.Credentials = MyCredentialCache
>
> ' Specify the PROPPATCH method.
> PROPPATCHRequest.Method = "PROPPATCH"
>
> ' Set the content type header.
> PROPPATCHRequest.ContentType = "text/xml"
>
> ' Encode the body using UTF-8.
> bytes = System.Text.Encoding.UTF8.GetBytes(strApptRequest)
>
> ' Set the content header length. This must be
> ' done before writing data to the request stream.
> PROPPATCHRequest.ContentLength = bytes.Length
>
> ' Get a reference to the request stream.
> PROPPATCHRequestStream = PROPPATCHRequest.GetRequestStream()
>
> ' Write the message body to the request stream.
> PROPPATCHRequestStream.Write(bytes, 0, bytes.Length)
>
> ' Close the Stream object to release the connection
> ' for further use.
> PROPPATCHRequestStream.Close()
>
> ' Create the appointment in the Calendar folder of the
> ' user's mailbox.
> PROPPATCHResponse = CType(PROPPATCHRequest.GetResponse(),
> HttpWebResponse) ' The remote server returned an error: (403)
> Forbidden
>
> MessageBox.Show("Appointment successfully created.")
>
> ' Clean up.
> PROPPATCHResponse.Close()
>
> Catch ex As Exception
> ' Catch any exceptions. Any error codes from the PROPPATCH
> ' or MOVE method requests on the server will be caught
> ' here, also.
> MessageBox.Show(ex.Message)
>
> End Try
> End Sub
>
> TIA
>
date: Mon, 30 Jan 2006 14:14:08 +0100
author: Michael
|
|