Creating an appointment (WebDav)
Exchange Server Forum Index Exchange Server
Discussion forums for Microsoft Exchange Server users.
Microsoft Outlook
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web ExchangeServerHelp.com
Creating an appointment (WebDav)

 
Post new topic   Reply to topic    Exchange Server Forum Index -> Development
Author Message
Simon Allport
Guest





Posted: Mon Nov 22, 2004 9:25 pm    Post subject: Creating an appointment (WebDav) Reply with quote

I saw the MSDN article "creating an appointment using webdav. But I get an
The remote server returned an error: (401) Unauthorized.System. Though my
server permissions are all correct.

If anyone knows why this happening please can you let me know.

I haved pasted the code below
Sub Main()

' 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
' Exchange server name
strExchSvrName = "ExchangeServer"

' Mailbox folder name.
strMailbox = "user"

' Appointment item.
strApptItem = "testappointment.eml"

' URI of the user's calendar folder.
strCalendarUri = "http://" & strExchSvrName & "/exchange/" & _
strMailbox & "/Calendar/"

' User name and password of appointment creator.
strUserName = "user"
strDomain = "Domain"
strPassword = "!Password"

' 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. See the documentation on
the properties
' in the urn:schemas:calendar: for more information.
strCalInfo = "<cal:location>meetappt Location</cal:location>" & _
"<cal:dtstart
dt:dt=""dateTime.tz"">2004-05-18T23:00:00.000Z</cal:dtstart>" & _
"<cal:dtend
dt:dt=""dateTime.tz"">2004-05-18T23: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>"

' 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), _
"NTLM", _
New System.Net.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(),
System.Net.HttpWebResponse)

Console.WriteLine("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.
Console.WriteLine(ex.Message)

End Try

End Sub

Back to top
Henning Krause [MVP]
Guest





Posted: Mon Nov 22, 2004 10:47 pm    Post subject: Re: Creating an appointment (WebDav) Reply with quote

Hello,

since you are using NTLM this might happen if the request flows over a proxy
or similar.

Or simply, NTLM authentication is disabled on the folder.

Try to use Basic authentication instead.

Greetings,
Henning Krause [MVP]
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/?page=products)


"Simon Allport" <Simon Allport@discussions.microsoft.com> wrote in message
news:F954A2F4-A559-4DD4-8B16-D9034F152905@microsoft.com...
Quote:
I saw the MSDN article "creating an appointment using webdav. But I get an
The remote server returned an error: (401) Unauthorized.System. Though my
server permissions are all correct.

If anyone knows why this happening please can you let me know.

I haved pasted the code below
Sub Main()

' 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
' Exchange server name
strExchSvrName = "ExchangeServer"

' Mailbox folder name.
strMailbox = "user"

' Appointment item.
strApptItem = "testappointment.eml"

' URI of the user's calendar folder.
strCalendarUri = "http://" & strExchSvrName & "/exchange/" & _
strMailbox & "/Calendar/"

' User name and password of appointment creator.
strUserName = "user"
strDomain = "Domain"
strPassword = "!Password"

' 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. See the documentation on
the properties
' in the urn:schemas:calendar: for more information.
strCalInfo = "<cal:location>meetappt Location</cal:location>" & _
"<cal:dtstart
dt:dt=""dateTime.tz"">2004-05-18T23:00:00.000Z</cal:dtstart>" & _
"<cal:dtend
dt:dt=""dateTime.tz"">2004-05-18T23: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>"

' 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), _
"NTLM", _
New
System.Net.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(),
System.Net.HttpWebResponse)

Console.WriteLine("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.
Console.WriteLine(ex.Message)

End Try

End Sub

Back to top
Michael
Guest





Posted: Mon Nov 22, 2004 11:02 pm    Post subject: Re: Creating an appointment (WebDav) Reply with quote

Do you have any additional error message?
Sometimes is a problem to make trust relationship between client and server

Michael
-------------------------------
If you need WebDAV API for Exchange server, use our component "WebDAV .NET
for Exchange".
Check out http://www.independentsoft.com


"Simon Allport" <Simon Allport@discussions.microsoft.com> wrote in message
news:F954A2F4-A559-4DD4-8B16-D9034F152905@microsoft.com...
Quote:
I saw the MSDN article "creating an appointment using webdav. But I get an
The remote server returned an error: (401) Unauthorized.System. Though my
server permissions are all correct.

If anyone knows why this happening please can you let me know.

I haved pasted the code below
Sub Main()

' 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
' Exchange server name
strExchSvrName = "ExchangeServer"

' Mailbox folder name.
strMailbox = "user"

' Appointment item.
strApptItem = "testappointment.eml"

' URI of the user's calendar folder.
strCalendarUri = "http://" & strExchSvrName & "/exchange/" & _
strMailbox & "/Calendar/"

' User name and password of appointment creator.
strUserName = "user"
strDomain = "Domain"
strPassword = "!Password"

' 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. See the documentation on
the properties
' in the urn:schemas:calendar: for more information.
strCalInfo = "<cal:location>meetappt Location</cal:location>" & _
"<cal:dtstart
dt:dt=""dateTime.tz"">2004-05-18T23:00:00.000Z</cal:dtstart>" & _
"<cal:dtend
dt:dt=""dateTime.tz"">2004-05-18T23: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>"

' 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), _
"NTLM", _
New
System.Net.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(),
System.Net.HttpWebResponse)

Console.WriteLine("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.
Console.WriteLine(ex.Message)

End Try

End Sub



Back to top
 
Post new topic   Reply to topic    Exchange Server Forum Index -> Development All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server Dedicated Servers
New Topics Powered by phpBB