Event sink registration via WebDAV



Hi,

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
myCredentialCache = null;
HttpWRequest = null;
HttpWResponse = null;
QueryStream = null;
strm = null;
sr = null;
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
}
.



Relevant Pages

  • Re: The namespace, , is a duplicate error when compiling .NET Webservice
    ... Please post the entire exception, complete with stack trace and inner ... the current web request. ... mapping, String ns, Boolean isAny, XmlSchemaElement element) +762724 ... type, HttpContext context, HttpRequest request, HttpResponse response, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Event sink registration via WebDAV
    ... string myExchange = "http://exdevel2k3/exchange/";; ... HttpWebRequest HttpWRequest = WebRequest.Create; ... // Set the request timeout to 5 minutes ... Stream QueryStream = HttpWRequest.GetRequestStream; ...
    (microsoft.public.exchange2000.development)
  • Re: HttpWebRequest.GetRequestStream times out
    ... When I encounter this exception, this is printed in the log: ... Stream sendStream = httpReq.GetRequestStream; ... you never read more than 1 kB of the response, ... The request timeout is set to 100 seconds, and the requests that time out ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Problems installing Microsoft .NET Framework 1.1 Service Pack
    ... and it worked and I have filled in the request and sent it. ... An unhandled exception occurred during the execution of the ... siteName, String httpVerb, String path, String QS, String httpVersion, ... request, String site, TicketState& ticketState, String& responseHeaders) +100 ...
    (microsoft.public.windowsupdate)
  • Re: Problems installing Microsoft .NET Framework 1.1 Service Pack
    ... and it worked and I have filled in the request and sent it. ... An unhandled exception occurred during the execution of the ... siteName, String httpVerb, String path, String QS, String httpVersion, ... request, String site, TicketState& ticketState, String& responseHeaders) ...
    (microsoft.public.windowsupdate)

Loading