These are the methods from our XMLHTTPRequest class
public void Open(string Method, string Url, bool Asynch, string User, string
Password)
{
// check parameters
if (lgRequest != null)
throw new InvalidOperationException("Connection Already open");
if (Url == "" || Url==null)
throw new ArgumentNullException("URL must be specified");
System.Uri uriObj = new System.Uri(Url);
if (!((uriObj.Scheme == System.Uri.UriSchemeHttp) || (uriObj.Scheme ==
System.Uri.UriSchemeHttps)))
throw new ArgumentOutOfRangeException("URL Scheme is not http or https");
//if (Method==null || (Method.ToUpper()!="POST" && Method.ToUpper()!="GET"
&& Method.ToUpper()!="PUT" && Method.ToUpper()!="PROPFIND" &&
Method.ToUpper()!="PROPPATCH" && Method.ToUpper()!="SEARCH"))
if (Method==null)
throw new ArgumentOutOfRangeException("Method argument type not defined");
lgbIsAsync = Asynch;
lgRequest = (HttpWebRequest)WebRequest.CreateDefault(uriObj);
lgRequest.Method = Method;
lgRequest.ContentType = "text/xml";
if (User != "")
lgRequest.Credentials = new System.Net.NetworkCredential(User, Password);
else
//lgRequest.Credentials = CredentialCache.DefaultCredentials;
lgRequest.Credentials =
CredentialCache.DefaultCredentials.GetCredential(uriObj, "Windows
Integrated");
uriObj = null;
lgReadyState = eReadyState.LOADING;
}
// here are two points at which the exception may occur (but five minutes
later it may work)
public void Send(string body)
{
if (lgReadyState != eReadyState.LOADING)
throw new InvalidOperationException("Sending a message is not allowed at
this ReadyState");
if (body != null)
{
if(lgbIsAsync)
{
lgMsg = body;
IAsyncResult res = lgRequest.BeginGetRequestStream(new
AsyncCallback(ReqCallback),lgRequest);
lgReadyState = eReadyState.LOADED;
}
else
{
UTF8Encoding encoding = new UTF8Encoding();
byte[] buffer = encoding.GetBytes(body);
lgRequest.ContentLength = buffer.Length;
Stream stream = lgRequest.GetRequestStream(); // exception 501 (point one)
stream.Write(buffer,0,buffer.Length);
stream.Close();
lgResponse = (HttpWebResponse)lgRequest.GetResponse(); // sometimes
exception 501 at this point
lgReadyState = eReadyState.COMPLETED;
}
}
}
This ist the method from our business layer (contents of str=xml data of
appointment below)
Public Shared Sub SendPersonalUrlaubAppointment(ByVal itm As Urlaubsmeldung,
ByVal User As String, ByVal Pwd As String, ByVal Subject As String, ByVal
Mailbox As String, ByVal userServer As String)
Dim strAppURLKalender As String = "http://" + userServer +
"/Exchange/" + Mailbox + "/Kalender/" + System.Guid.NewGuid.ToString + ".EML"
Dim strAppURLCalender As String = "http://" + userServer +
"/Exchange/" + Mailbox + "/calendar/" + System.Guid.NewGuid.ToString + ".EML"
Dim s As New SenderAppointment
With s.objProp.objProps
.MailSubject = itm.Urlaub
.OLEndDate = itm.OutlookEndDate
.OLStartDate = itm.OutlookStartDate
.TextDescription = "Ich bin auf " + itm.Urlaub
End With
Dim ser As New XmlSerializer(GetType(SenderAppointment))
Dim xml As New XMLHTTP.XMLHttpRequest
Dim m As New MemoryStream
Dim sw As New XmlTextWriter(m, System.Text.Encoding.UTF8)
Dim sr As New StreamReader(m)
ser.Serialize(m, s)
Try
xml.Open("PROPPATCH", strAppURLKalender, False, User, Pwd)
Catch ex1 As Exception
xml.Open("PROPPATCH", strAppURLCalender, False, User, Pwd)
End Try
xml.SetRequestHeader("Content-Type", "text/xml")
m.Position = 0
Dim str As String = sr.ReadToEnd
xml.Send(str)
Dim strResult As String = xml.GetResponseXML.InnerXml
xml.Dispose()
sw.Close()
End Sub
//str
"<?xml version="1.0"?>
<propertyupdate xmlns:xsd="
http://www.w3.org/2001/XMLSchema"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xmlns="DAV:">
<set>
<prop>
<contentclass>urn:content-classes:appointment</contentclass>
<outlookmessageclass
xmlns="
http://schemas.microsoft.com/exchange/">IPM.Appointment</outlookmessageclass>
<location xmlns="urn:schemas:calendar:" />
<dtstart
xmlns="urn:schemas:calendar:">2005-09-01T00:00:00.0000000+02:00</dtstart>
<dtend
xmlns="urn:schemas:calendar:">2005-09-02T00:00:00.0000000+02:00</dtend>
<instancetype xmlns="urn:schemas:calendar:">0</instancetype>
<busystatus xmlns="urn:schemas:calendar:">OOF</busystatus>
<meetingstatus xmlns="urn:schemas:calendar:">TENTATIVE</meetingstatus>
<alldayevent xmlns="urn:schemas:calendar:">0</alldayevent>
<responserequested xmlns="urn:schemas:calendar:">1</responserequested>
<method xmlns="urn:schemas:calendar:">REQUEST</method>
<sequence xmlns="urn:schemas:calendar:">0</sequence>
<priority xmlns="urn:schemas:httpmail:">0</priority>
<read xmlns="urn:schemas:httpmail:">1</read>
<subject xmlns="urn:schemas:httpmail:">URLAUB</subject>
<textdescription xmlns="urn:schemas:httpmail:">Ich bin auf
URLAUB</textdescription>
</prop>
</set>
</propertyupdate>"
Joerg Jooss said:
Post your code. 501 usually means that a particular HTTP method (e.g.
PUT or DELETE) isn't implemented by the server.
Cheers,