EWS - Error subscribing to streaming notifications
i'm using sample code pointed @ glen's exchange dev blog, open streaming subscriptions new mail notifications via ews. i've changed little bit because want listen main inbox opposed particular folder i've changed subscribetostreamingnotifications subscribetostreamingnotificationsonallfolders, .dll path different it's version 2, , mailbox , credentials have been set. i'm trying working before it.
$mailboxname = "user@domain.com" $dllpath = "c:\program files\microsoft\exchange\web services\2.0\microsoft.exchange.webservices.dll" [void][reflection.assembly]::loadfile($dllpath) $service = new-object microsoft.exchange.webservices.data.exchangeservice([microsoft.exchange.webservices.data.exchangeversion]::exchange2010_sp1) $service.traceenabled = $false $service.credentials = new-object system.net.networkcredential("user@domain.com","password") $service.autodiscoverurl($mailboxname ,{$true}) $fldarray = new-object microsoft.exchange.webservices.data.folderid[] 1 $inboxid = new-object microsoft.exchange.webservices.data.folderid([microsoft.exchange.webservices.data.wellknownfoldername]::inbox,$mailboxname) $fldarray[0] = $inboxid $stmsubscription = $service.subscribetostreamingnotificationsonallfolders($fldarray, [microsoft.exchange.webservices.data.eventtype]::newmail) $stmconnection = new-object microsoft.exchange.webservices.data.streamingsubscriptionconnection($service, 30); $stmconnection.addsubscription($stmsubscription) register-objectevent -inputobject $stmconnection -eventname "onnotificationevent" -action { foreach($notevent in $event.sourceeventargs.events){ [string]$itmid = $notevent.itemid.uniqueid.tostring() $message = [microsoft.exchange.webservices.data.emailmessage]::bind($event.messagedata,$itmid) "subject : " + $message.subject + " " + (get-date) | out-file c:\temp\log2.txt -append } } -messagedata $service register-objectevent -inputobject $stmconnection -eventname "ondisconnect" -action {$event.messagedata.open()} -messagedata $stmconnection $stmconnection.open() the error i'm getting @ line 13 , saying 'cannot convert argument "0", value: "inbox (user@domain.com)", "subscribetonotificationsonallfolders" type "microsoft.exchange.webservices.data.eventtype": cannot convert "inbox (user@domain.com)" value of type "microsoft.exchange.webservices.data.folderid" type "microsoft.exchange.webservices.data..eventtype".
then tells me 2 lines down, exception calling "addsubscription" "1" argument(s): "value cannot null. parameter name: subscription.
@ line 15.
so somewhere (line 13 or above) i've not set value , it's stayed null - can me though because can't change script how need until can working base. when it's done can post results others.
thanks in advance.
hi bobbinspenguin,
i have no idea blog entry copied (and glen's blog source), function calling error not accept inboxes parameters, events, see documentation. i'd recommend comparing part blog entry again. either missed something, or glen made error (not likely, possible. if did make one, needs told).
cheers,
fred
ps.: more of ews specific problem, , you'll have lot better results posting in exchange development forums.
there's no place 127.0.0.1
Windows Server > Windows PowerShell
Comments
Post a Comment