Exchange
--
Questions
--
Followers
Top Experts
I get the error
The remote server returned an error: (409) Conflict.
Can anyone please tell me what might cause this?
Public Function AddToCalendar(ByVal MtgDate As Date, ByVal Loc As String, ByVal MtgName As String, ByVal InstrName As String)
' Variables.
Dim oRequest As HttpWebRequest
Dim oResponse As WebResponse
Dim MyCredentialCache As CredentialCache
Dim oRequestStream As System.IO.Stream
Dim sb As StringBuilder = New StringBuilder
Dim strCalendarUri As String = "http://ServerName/public/PublicCalendar/"
Dim apptStartTime As String = MtgDate.ToString("yyyy-MM-ddTHH:mm:ss")
Dim apptEndTime As String = MtgDate.ToString("yyyy-MM-ddTHH:mm:ss")
Dim strMailbox As String = String.Empty
strMailbox = "skallem@gosystemsinc.com"
' Appointment item.
Dim strApptItem As String = Guid.NewGuid().ToString() + ".eml"
' User name and password of appointment creator.
Dim strUserName As String = "Username"
Dim strPassword As String = "Password"
' XML namespace info for the WebDAV request.
Dim strXMLNSInfo As String = "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. 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.
Dim strCalInfo As String = "<cal:location>" & Loc & "</cal:location>" _
& "<cal:dtstart dt:dt=""dateTime.tz"">" _
& apptStartTime _
& "</cal:dtstart>" _
& "<cal:dtend dt:dt=""dateTime.tz"">" _
& apptEndTime _
& "</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.
Dim strHeaderInfo As String = "<header:to>" + strMailbox + "</header:to>"
' Set the subject of the appointment.
Dim strMailInfo As String = "<mail:subject>" _
& MtgName _
& "</mail:subject>" _
& "<mail:htmldescription>" _
& "Location: " _
& Loc _
& "</mail:htmldescription>"
' Build the XML body of the HTTP request.
Dim strApptRequest 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>" _
& strMailInfo _
& strCalInfo _
& "<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))
' Create the HttpWebRequest object.
oRequest = HttpWebRequest.Create(strCalendarUri + strApptItem)
' Add the network credentials to the request.
oRequest.Credentials = MyCredentialCache
' Specify the method.
oRequest.Method = "POST"
' Set the content header length. This must be
' done before writing data to the request stream.
oRequest.ContentLength = strApptRequest.Length
' Get a reference to the request stream.
oRequestStream = oRequest.GetRequestStream()
' Write the message body to the request stream.
oRequestStream.Write(Encoding.UTF8.GetBytes(strApptRequest), 0, strApptRequest.Length)
' Close the Stream object to release the connection
' for further use.
oRequestStream.Close()
' Set the content type header.
oRequest.ContentType = "text/xml"
'' Create the appointment in the Calendar folder of the
' user's mailbox.
oResponse = oRequest.GetResponse()
' Clean up.
oResponse.Close()
End Function
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
The remote server returned an error: (400) Bad Request.
Attached is the request as it is sent. Can someone figure out whats wrong ?
<?xml version="1.0"?><g:propertyupdate 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:"><g:set><g:prop><g:contentclass>urn:content-classes:appointment</g:contentclass><e:outlookmessageclass>IPM.Appointment</e:outlookmessageclass><mail:subject>Meeting </mail:subject><mail:htmldescription>Location: Office</mail:htmldescription><cal:location>Office</cal:location><cal:dtstart dt:dt="dateTime.tz">2011-08-18T10:30:00</cal:dtstart><cal:dtend dt:dt="dateTime.tz">2011-08-18T10:30:00</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><mapi:finvited dt:dt="boolean">1</mapi:finvited></g:prop></g:set></g:propertyupdate>
I set the datetime format as ""yyyy-MM-ddTHH:mm:ss.000Z
But the time in the appointment is saved as 2011-08-18 06:30:00
Also, when I try to set the time in PM like 17:00:00, it is throwing the Bad Request error.
How do I set the datetime format to work in EST?






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Something strange is happening though. The code is working right sometimes, and saving the appointment on Exchange. But sometimes its throwing the Bab Request (400) randomly. I have to refresh the application or just wait for sometime and it starts working again. What can possibly be the reason for such random error ?
but the request sent when the response failed and the request sent when the response succeeded were exactly the same. I have attached both the requests.
The problem doesn't seem to be with the request. Can it be something to do with the Exchange server? Also, can it be due to the order of the lines in the code ? I have attached the code again. Can you please let me know if you find anything else wrong in the code? The error is completely random.

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Then I saw a proper pattern. But that made things worse. The requests would look exactly the same but one of them would randomly return 400. I have attached 3 requests as example, one of them returning 400.
I checked all other websites apart from Default and none of them have a PROPATCH request. The Default Website has a bunch of sub-directories, one of which is "public" which is what I think I am accessing.
Do you think this is Normal or should I contact my Network admin ? It really doesn't look like the problem with the code but with the Exchange Server.
2011-08-08 19:49:53 192.123.1.1 PROPPATCH /public/PublicCalendar/fff2daed-7096-4b97-9fb2-cd3cdeab7d46.eml - 80 - 192.123.1.2 - 401 2 2148074254
2011-08-08 19:49:53 192.123.1.1 PROPPATCH /public/PublicCalendar/fff2daed-7096-4b97-9fb2-cd3cdeab7d46.eml - 80 Domain\Admin 192.123.1.2 - 207 0 0
2011-08-08 19:56:34 192.123.1.1 PROPPATCH /public/PublicCalendar/98b16a95-7390-435f-8aa0-d717481fd405.eml - 80 - 192.123.1.2 - 401 2 2148074254
2011-08-08 19:56:34 192.123.1.1 PROPPATCH /public/PublicCalendar/98b16a95-7390-435f-8aa0-d717481fd405.eml - 80 Domain\Admin 192.123.1.2 - 400 0 0
2011-08-08 19:56:47 192.123.1.1 PROPPATCH /public/PublicCalendar/49cf4c0a-faa1-44e1-925c-1e77630b656b.eml - 80 - 192.123.1.2 - 401 2 2148074254
2011-08-08 19:56:47 192.123.1.1 PROPPATCH /public/PublicCalendar/49cf4c0a-faa1-44e1-925c-1e77630b656b.eml - 80 Domain\Admin 192.123.1.2 - 207 0 0






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
http://www.getnetgoing.com/HTTP-400.html
Some of it is obviously not relevant, but something might be.
It's interesting that the subcode is 0 (so your error is really 400.0). Â The 0 subcode isn't valid for IIS, so it must be from the WebDAV ISAPI itself (it is known not be too helpful with its subcodes).
Exchange
--
Questions
--
Followers
Top Experts
Exchange is the server side of a collaborative application product that is part of the Microsoft Server infrastructure. Exchange's major features include email, calendaring, contacts and tasks, support for mobile and web-based access to information, and support for data storage.