Re: Event sink registration via WebDAV

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hello,

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" <makom.news@xxxxxxxx> wrote in message news:44fc1fe5$0$5158$9b4e6d93@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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

  • Event sink registration via WebDAV
    ... The exception: "The remote server returned an error Method not allowed" at line 68. ... string myExchange = "http://exdevel2k3/exchange/";; ... // Set the request timeout to 5 minutes ... Stream QueryStream = HttpWRequest.GetRequestStream; ...
    (microsoft.public.exchange2000.development)
  • Re: Problems creating real contacts with WebDAV
    ... HttpWebRequest HttpWRequest = WebRequest.Create ... CredentialCache myCredentialCache = new CredentialCache; ... //Set the request timeout to 5 minutes. ... // write the data to be posted to the Request Stream ...
    (microsoft.public.exchange2000.development)
  • Re: Problems creating real contacts with WebDAV
    ... HttpWebRequest HttpWRequest = WebRequest.Create ... CredentialCache myCredentialCache = new CredentialCache; ... //Set the request timeout to 5 minutes. ... Stream QueryStream = HttpWRequest.GetRequestStream; ...
    (microsoft.public.exchange2000.development)
  • Sending a XML string from C# app in PPC
    ... I am sending a simple xml string to a PHP ... // Create a request using a URL that can receive a post. ... // Get the request stream. ... // Get the response. ...
    (microsoft.public.pocketpc.developer)
  • Re: asp.net page read response from another site?
    ... string url = http://www.somesite.com/somepage.html; ... You can also process the stream as it comes across. ... I wanted to make a page where I can send a request to another page, ... and read it's response back, can someone point me to an example? ...
    (microsoft.public.dotnet.framework.aspnet)