Event sink registration via WebDAV

Event sink registration via WebDAV

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


i,

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()
{
try
{
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
System.Net.CredentialCache();
myCredentialCache.Add(new System.Uri(myUri),
"NTLM",
new System.Net.NetworkCredential(myUserName, myPassword,
myDomain)
);

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

string strQuery;
strQuery = "<?xml version=\"1.0\"?>";
strQuery += "<g:propertyupdate xmlns:g='DAV:'
xmlns:ev='http://schemas.microsoft.com/exchange/events/'>";
strQuery += "<g:set><g:prop>";
strQuery +=
"<g:contentclass>urn:content-class:storeeventreg</g:contentclass>";
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);
QueryStream.Close();

// 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();
Console.WriteLine(sReqHeaders);

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

// Close Stream
strm.Close();

// Clean Up
myCredentialC
 
 
 

Event sink registration via WebDAV

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

ello,

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 -
http://www.infinitec.de/software/nettoolbox/infinitec.exchange.aspx


"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
Martin
 
 
 

Event sink registration via WebDAV

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

Hello,

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 -
http://www.yqcomputer.com/