PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : WebDAV, CalDAC - Wie nehme ich richtig Verbindung mit einem CalDAV Server auf ?


BigKid
2014-07-04, 12:36:36
Hiho,

Kurzfassung:
Ich suche Hilfe beim Zugriff auf meinen CommunigateServer per C#. Fern-Ziel ist es Termine abzufragen und zu setzen...
Die aktuelle Problemstellung unter der "Langfassung"...

Langfassung:
da meine Firma seit neusten leider Private-Endgeräte nur noch mit FußfesselApp an den Outlook Server läßt suche ich einen Weg meine Termine auf meinen neuen Communigate Server zu synchronisieren. Outlook WebAcess ist noch offen und ich habe schon alles zusammen um Termine von dort abzufragen.

Das ganze ist ein Hobby Projekt also bin ich erstmal nicht an fertiger Software interessiert.

Mein Hintergrund (damit ihr mich einschätzen könnt - nicht um "aufzutragen" ;) ):
Das ganze in C#. Ich bin Dipl. Inf (techn. Informatik) (FH) aber etwas eingerostet. Was http requests, WebDav und Caldav betrifft stehe ich am Anfang bin aber normalerweise recht fix mich in sowas einzuschaffen.

Aktuelle Problemstellung:
Wie frage ich den "richtigen" Einstiegsknoten von meinem Communigate Server ab ?
Theoretisch soll man wohl ein PROPFIND auf current-user-principal machen... Allerdings bekomme ich da immer eine Antwort die Anzeigt, dass ich nicht authentifiziert wäre... Das hier ist der Code:



System.Net.HttpWebRequest Request;
System.Net.WebResponse Response;
System.Net.CredentialCache MyCredentialCache;
string strBody = "";
byte[] bytes = null;
System.IO.Stream RequestStream = null;
System.IO.Stream ResponseStream = null;
XmlDocument ResponseXmlDoc = null;
XmlNodeList CalendarHomeSet = null;

// Build the PROPFIND request body.
strBody = "<?xml version=\"1.0\"?>"
+ "<d:propfind xmlns:d='DAV:'><d:prop><d:current-user-principal /></d:prop>"
+ "</d:propfind>";

// 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(strSrcURI),
"NTLM",
new System.Net.NetworkCredential(strUserName, strPassword, strDomain)
);

// Create the HttpWebRequest object.
Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(strSrcURI);

// Add the network credentials to the request.
Request.Credentials = MyCredentialCache;
Request.PreAuthenticate = true;

// Specify the method.
Request.Method = "PROPFIND";

// accept all certificates
Request.ServerCertificateValidationCallback = ValidateServerCertificate;

// Encode the body using UTF-8.
bytes = Encoding.UTF8.GetBytes((string)strBody);

// Set the content header length. This must be
// done before writing data to the request stream.
Request.ContentLength = bytes.Length;

// Get a reference to the request stream.
RequestStream = Request.GetRequestStream();

// Write the request body to the request stream.
RequestStream.Write(bytes, 0, bytes.Length);

// Close the Stream object to release the connection
// for further use.
RequestStream.Close();

// Set the content type header.
Request.ContentType = "text/xml";

// Send the PROPFIND method request and get the
// response from the server.
Response = (HttpWebResponse)Request.GetResponse();

// Get the XML response stream.
ResponseStream = Response.GetResponseStream();

// Create the XmlDocument object from the XML response stream.
ResponseXmlDoc = new XmlDocument();
ResponseXmlDoc.Load(ResponseStream);

// Clean up.
ResponseStream.Close();
Response.Close();



Und das hier die Antwort:

<?xml version="1.0"?><D:multistatus xmlns:D="DAV:">
<D:response>
<D:href>/</D:href>
<D:propstat>
<D:prop>
<D:current-user-principal><D:unauthenticated /></D:current-user-principal>
</D:prop>
<D:status>HTTP/1.1 200 OK</D:status>
</D:propstat>
</D:response>
</D:multistatus>

BigKid
2014-07-05, 11:33:26
Mittlerweile bin ich wesentlich weiter... Falls hier doch jemand mit liest...
Werde es bei Gelegenheit aktialisieren...

Das neuste "Problem" ist nun der Umgang mit den Antworten des Servers...
Klasse drumm rumm stricken oder mit xpath fummeln...