Event sink registration via WebDAV

Event sink registration via WebDAV

Post by Martin Kom » Tue, 05 Sep 2006 21:45:24


I have changed some example code for registering an exchange-event-sink,
but it doesnt work! Can somebody please tell me what is wrong here?

The exception: "The remote server returned an error (405) Method not
allowed" at line 68.

public static void RegisterEventSink()
string myUserName = "user1";
string myPassword = "user1";
string myDomain = "Domain";
string myExchange = "http://exdevel2k3/exchange/";
string myUri = myExchange + myUserName + "/Inbox/";

// Create a new CredentialCache object and fill it with the network
// credentials required to access the server.
CredentialCache myCredentialCache = new
myCredentialCache.Add(new System.Uri(myUri),
new System.Net.NetworkCredential(myUserName, myPassword,

System.Uri Uri = new System.Uri(myUri);
HttpWebRequest HttpWRequest =

string strQuery;
strQuery = "<?xml version=\"1.0\"?>";
strQuery += "<g:propertyupdate xmlns:g='DAV:'
strQuery += "<g:set><g:prop>";
strQuery +=
strQuery += "<ev:EventMethod>OnSyncSave</ev:EventMethod>";
strQuery += "<ev:SinkClass>TPMExEvents.TPMExEv.1</ev:SinkClass>";
strQuery += "<ev:matchScope>SHALLOW</ev:matchScope>";
strQuery += "</g:prop></g:set>";
strQuery += "</g:propertyupdate>";

HttpWRequest.Credentials = myCredentialCache;

// Set Headers
HttpWRequest.KeepAlive = false;
HttpWRequest.Headers.Set("Pragma", "no-cache");
HttpWRequest.ContentType = "text/xml";
HttpWRequest.ContentLength = strQuery.Length;

// Set the request timeout to 5 minutes
HttpWRequest.Timeout = 300000;

// Set the request method
HttpWRequest.Method = "MKCOL";

// Store the data in a byte array
byte[] ByteQuery = System.Text.Encoding.ASCII.GetBytes(strQuery);
HttpWRequest.ContentLength = ByteQuery.Length;
Stream QueryStream = HttpWRequest.GetRequestStream();

// Write the data to be posted to the Request Stream
QueryStream.Write(ByteQuery, 0, ByteQuery.Length);

// Send Request and Get Response
HttpWebResponse HttpWResponse =
(HttpWebResponse)HttpWRequest.GetResponse();//<-- Exception here (l.68)

// Get the Status code
int iStatCode = (int)HttpWResponse.StatusCode;
string sStatus = iStatCode.ToString();
Console.WriteLine("Status Code: {0}", sStatus);

// Get the request headers
string sReqHeaders = HttpWRequest.Headers.ToString();

// Read the Response Steam
Stream strm = HttpWResponse.GetResponseStream();
StreamReader sr = new StreamReader(strm);
string sText = sr.ReadToEnd();
Console.WriteLine("Response: {0}", sText);

// Close Stream

// Clean Up

Event sink registration via WebDAV

Post by Henning Kr » Tue, 05 Sep 2006 23:30:55


I don't know if you have set all properties... but MKCOL is definitely the
wrong method.

Use PROPPATCH instead - the event item is an item, not a folder.

Best regards,
Henning Krause

Visit my website: http://www.infinitec.de
Exchange access library -

"Martin Komischke" < XXXX@XXXXX.COM > wrote in message
news:44fc1fe5$0$5158$ XXXX@XXXXX.COM ...


Event sink registration via WebDAV

Post by Martin Kom » Tue, 05 Sep 2006 23:44:26

Henning Krause schrieb:

Hello Henning,

indeed that was a mistake. Can you tell me where to find some more
information about creating items on an exchange-server via WebDAV. I
adapted the EventSinkRegistration via WebDAV script from MSDN. But this
on is in VB I would like to have a C# Libary.

I think there is a problem in my code that deals with the name of the
item. Where and how do I set the name of the event sink item?

thanks and regards

Event sink registration via WebDAV

Post by Henning Kr » Wed, 06 Sep 2006 01:21:36


I have an access library which uses WebDAV for the access. Since the source
code is included, you can take a look on how it is done.

Generally, see the Exchange SDK
( http://www.yqcomputer.com/ ).

Best regards,
Henning Krause

Visit my website: http://www.yqcomputer.com/
Exchange access library -