Uri uri = new Uri("http://domain/MyPage.aspx");
PushSubscription ps = service.SubscribeToPushNotifications(folder, uri, 1, "", EventType.Created, EventType.Modified, EventType.Deleted);
Now i get a hit on domain/MyPage.aspx when i change a event from calendar.
But now how i process that response ? There is limited value in request header. how could i know that which calendar, which service this request come. How i fetch values from this URL hit.
I need C# code to get all information when exchange hit my web page.
When you created the Subscription you would have received a subscription Id, you need to save that information somewhere and then use that to correlate that back to Mailbox/Folder when you receive the Push Response which will contain the SubscriptionId that the Push belongs to.
Yes I know this and I am getting subscription Id successfully.
But my question is that how I fetch these value when I receive the Push Response. From where I get these information.
I am developing web application in C#, I checked these value in Request.header, but nothing is there.
Glen, Please help me. I am stuck here.
That information isn't in the Push response that why you need to save this information when you created the Subscription eg I create a Subscription for the Inbox for Fred@domain.com and I receive a SubscriptionId in response I then need to save this information so the endpoint that receives the push knows what Mailbox the Push request with SubscriptionId belongs to. So when your service gets the Push it will have the SubscriptionId and ItemId of the Item that changed etc. That response wont tell you what mailbox it belongs to so its up to you service to work it out based on the SubscriptionId.
I save my SubscriptionId when i create Subscription.
Now as you says when my service gets the Push it will have the SubscriptionId and ItemId of the Item that changed etc.
But my question is that from where I get SubscriptionId and ItemId in response ?
How I read response ? I am unable to read response.
Sorry I don't understand your question eg
>>I save my SubscriptionId when i create Subscription.
Okay with you here you create a subscription and you save the Subscription Id and FolderId and Mailbox you made the subscription on ?
>>Now as you says when my service gets the Push it will have the SubscriptionId and ItemId of the Item that changed etc.
Okay so the Push request will contain the SubscriptionId and ItemId >> But my question is that from where I get SubscriptionId and ItemId in response ? How I read response ?
What response are you talking about ? can you post and example response ? you will get Push request from the server with the subscriptionId and ItemId when a change occurs, you won't get anything else other then this (apart from heartbeat). If you want information on the Item that caused the notification you will need to make a GetItem request for the ItemId that caused the Push. If you have multiple users and need to impersonate the owner of the Mailbox where this item is located this is when you need to use the Subscriptionid you saved before to work out what Mailbox this push notification belongs to so you can then set the impersonation header correctly etc.
Let me clear my question.
>> I save my
service.SubscribeToPushNotifications(folder, "www.mydomain.com/ExchangeNotification.aspx", 1, "", EventType.Created);
Now I Get the Push request on www.mydomain.com/ExchangeNotification.aspx when a event is created on calendar.
Now my question arise :
In Page ExchangeNotification.aspx, where is myHow I can fetch these value ?
This is my C# ExchangeNotification.aspx page code
protected void Page_Load(object sender, EventArgs e)
// Where is my SubscriptionId and ItemId
// Request.Header ,,,, there is no SubscriptionId and ItemId in request
A Push notification will be sent to your end point as a SendNotification and you endpoint needs to deal with processing it (eg parsing the SOAP Message). It a SOAP message like all EWS request but its posted from the Exchange server to your endpoint so your code needs to deal with it there are a number of sample listeners on https://blogs.msdn.microsoft.com/emeamsgdev/2011/08/19/ews-push-notification-example-application/ .
Examples which you provide me, is not fully helpful. these are window application where we need to give our ipaddress and port to receive push notification. which is not to easy.
But, I got this.
I found it in Request.InputStream
StreamReader stream = new StreamReader(Request.InputStream);
string x = stream.ReadToEnd();
string xml = HttpUtility.UrlDecode(x);
here in XML string, i found all information.
Glen, i have further one more question.
Now, how I send to OK response to exchange api OR Unscribe response to exchange ?
Your listener needs to respond to the POST from the server with the SendNotificationResultType SOAP message if you look at the way the samples does it or http://exchangenotification.codeplex.com/ you will need to implement something simular. To unsubscribe you need to respond with Unsubscribe in the Heatbeat instead of okay else it will disappear itself after 3 failures.
Thanks for the reply.
I am unable to send Ok notification to exchange. From where I POST my response. WHAT is the URL.
Below is my code. please have a look.
string oRequest = "";
oRequest = "<?xml version=\"1.0\" encoding=\"UTF - 8\"?>";
oRequest += "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\" xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">";
oRequest += "<soap:Body><m:SendNotificationResult><m:SubscriptionStatus>Ok</m:SubscriptionStatus></m:SendNotificationResult></soap:Body>";
oRequest += "</soap:Envelope>";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("This is the URL which i provide to exchange when i create subricption. Is this wrong, What will be the URL");
req.ContentType = "text/xml; charset=\"utf-8\"";
req.Accept = "text/xml";
req.Method = "POST";
//Passes the SoapRequest String to the WebService
using (Stream stm = req.GetRequestStream())
using (StreamWriter stmw = new StreamWriter(stm))
//Gets the response
WebResponse response = req.GetResponse();
//Writes the Response
Stream responseStream = response.GetResponseStream();
StreamReader sr = new StreamReader(responseStream);
string s = sr.ReadToEnd();
Glen, If possible please help with C# code.
I also refer below article, but not success.
You need to respond to the Push call you can't just post a request back eg
Listener gets POST from Server the response back to that POST is the Okay or Unsubscribe in SOAP. This is why people typically use a WCF or SOAP webservice as a listener as they will handle the SOAP response (there are multiple samples for doing this). In your example your website will need to respond with a SOAP response (which is just XML) to the Exchange Server Push http://stackoverflow.com/questions/543319/how-to-return-xml-in-asp-net but I've never seen anybody take that approach.
Thank you very much. Now It's working for me. Thanks for your support.
One last query. If we not send OK or Unsubscribe response then after three attempt our subscription is expire.
Is there is any time out or time limit to expire the watch even I am sending Ok response each time ?
Suppose I create today subscription and on every push request I am sending Ok response. So after one or Two month, my subscription is remain active or it's expire after some time ?
There is no expiry for Push notifications however your listener should be watching out for instances where your subscription in nolonger valid (eg if you don't get heartbeat within a cetain period that means the subscription would need to be recreated). Eg if somebody restarts the CAS Role Exchange server as part of normal Windows or Exchange servicing then your subscription will just stop.
Thanks for update.
I have one more question here :
Initially I test my code on locally and getting PUSH response on my URL after subscribe Push notification.
But Now i deploy my code on server and now I am not getting any push request on my URL.
Is I need to register my Push notify URL on exchange. If Yes then where I have to register and whats the process ?
>> Is I need to register my Push notify URL on exchange. If Yes then where I have to register and whats the process ?
No its most likely firewall related eg the Exchange server needs to be able to access the server your running this eg the Exchange server initiates the connection so that listener must publish that port through the firewall,proxies etc. You might want to look at something like http://www.infinitec.de/post/2009/06/21/Troubleshooting-Push-notifications-failures.aspx to test it
Glen I am facing a issue from 3 months ago regarding to shared calendar.
I also post my query in various blog, but unable to get any help. below is my post :
here is my code :
The Result in ffolders, there is only 2-3 calendar, but there is many calendar which are shared with me by another people.
Some in OtherCalendar folder, Some in SharedCalendar folder. These calendar are visible in my outlook client.
I am also go through here :
But this not help me.