Up Additional code samples
DevForce 2010 Resource Center » Code samples » Additional code samples » Code sample: Push notification (Silverlight) (WPF)

Code sample: Push notification (Silverlight) (WPF)

Last modified on August 15, 2012 17:20

This sample shows how a DevForce client can subscribe to server-side events.



Problem

You may want to know when an event has occurred on the server. Perhaps an Entity of interest has been updated, or new rows have been added to the database. Instead of polling for the data from the client, you can publish a server-side event and let clients subscribe to that event and be notified when it occurs.

Solution

A sample application, in both Silverlight and WPF versions, which shows how the Push feature of DevForce can be used.  The sample shows two simple "notification services":  one which shows periodic status updates from a long running process, and the other which shows occasional notification messages based on user-supplied criteria.

Setup and Configuration

Silverlight considerations

The PollingDuplexHttpBinding from the Silverlight 4 SDK is used in the sample.  (net.tcp can also be used for duplex communications such as Push, but we don't provide a sample for this.)  You'll need to add a reference to the System.ServiceModel.PollingDuplex.dll assembly in both your Silverlight and web projects, but note that there are client and server versions of this assembly.  You'll find the assemblies in the subfolders of "<programfiles>\Microsoft SDKs\Silverlight\v4.0\Libraries".

The Silverlight application must also include a reference to IdeaBlade.EntityModel.Push.SL.  There are no additional assemblies required in the web application.

No special configuration is required on the Silverlight client to use Push with DevForce defaults.  See below for server configuration.

WinClient considerations

When using duplex http, you must provide the port number to which the server will send Push messages to the client.  You do so via the notificationService element in the ideablade.configuration section of the client application app.config:

XML
<notificationService clientPort="9012"/>

You can use any open port number.  Be sure the port is not already in use, and you will also need to open the port in your firewall.  

The "enabled" flag on this element can be used but has no affect on the client, as you "enable" Push on the client by calling EntityManager.RegisterCallback to subscribe to a "service" on the server.

TCP may also be used for the Push service, but is not shown in the samples.

Server considerations

In the web.config, to enable Push with DevForce defaults, add the following to the ideablade.configuration section:

XML
<notificationService enabled="true" />

This flag indicates to DevForce to begin listening for client requests for Push services.  DevForce uses your license and the setting of the SupportedClientApplicationType to determine the URLs of the endpoints:  if the setting is for "Both" and your license allows it, then endpoints will be defined to allow both Silverlight and WinClient client applications to use Push.  Otherwise, an endpoint is defined to allow only clients for the appropriate client application type.  The endpoint addresses will be in the form:

           http://localhost:9009/EntityServer.svc/NotificationService
           http://localhost:9009/EntityServer.svc/sl-NotificationService

Note that the host name and port will be the same as that used by your EntityServer.  Also note that the NotificationService (or Push) is a feature of the EntityServer.  If you use data source extensions, and therefore have multiple EntityServers running, each will also define the appropriate Push endpoints.  For example:

           http://localhost:9009/EntityServer_abc.svc/sl-NotificationService
           http://localhost:9009/EntityServer_abc.svc/NotificationService

Note that this setup is all performed for you by DevForce if the defaults are sufficient (described below).  If not, you can define your services using the serviceModel section of the configuration file, or implement a custom ServiceHostEvents class.

Default configuration

Silverlight

Client

The same protocol scheme used for the EntityServer is used by Push.  (Http, https and net.tcp are supported.)
       If http or https:
          PollingDuplexHttpBinding
              PollingDuplexMode = MultipleMessagesPerPoll
              InactivityTimeout = 1 hour
              ReceiveTimeout = 1 hour
              MaxReceivedMessageSize = int.maxvalue
              MaxBufferSize = int.maxvalue
              if https:  Security.Mode = Transport

       If net.tcp:
          CustomBinding
              BinaryMessageEncoding
             TcpTransport
                MaxReceivedMessageSize = int.maxvalue
                MaxBufferSize = int.maxvalue

Server

The same protocol scheme used by the EntityServer is used by Push.  (Http, https and net.tcp are supported.)
       If http or https:
          PollingDuplexHttpBinding
              PollingDuplexMode = MultipleMessagesPerPoll
              InactivityTimeout = 1 hour
              ReceiveTimeout = 1 hour
              MaxOutputDelay = 3 seconds
              MaxReceivedMessageSize = int.maxvalue
              MaxBufferSize = int.maxvalue
              If https:  Security.Mode = Transport

Note when using MultipleMessagesPerPoll that messages are streamed in 32k chunks. The maxOutputDelay ensures that messages are flushed from the pipeline on a timely basis, but you may want to adjust this for your application.  See the section on customizing configuration below for more information.

       If net.tcp:
          NetTcpBinding
             Security.Mode = none
             ReliableSession.Enabled = false
             MaxReceivedMessageSize = int.maxvalue
             MaxBufferSize = int.maxvalue

WinCient

Client

The same protocol scheme used for the EntityServer is used by Push.  (Http and net.tcp are supported.)
       If http:
         WsDualHttpBinding
             MessageEncoding = Mtom
             Security.Mode = none
             InactivityTimeout = timespan.maxvalue
             ReceiveTimeout = timespan.maxvalue
             MaxReceivedMessageSize = int.maxvalue
             MaxBufferSize = int.maxvalue
             ClientBaseAdddress = http://machinename:clientPort/guid

       If net.tcp:
           NetTcpBinding
              Security.Mode = none
              ReliableSession.Enabled = false
              MaxReceivedMessageSize = int.maxvalue
              MaxBufferSize = int.maxvalue

Server

The same protocol scheme used by the EntityServer is used by Push.  (Http and net.tcp are supported.)
       If http:
         WsDualHttpBinding
             MessageEncoding = Mtom
             Security.Mode = none
             InactivityTimeout = timespan.maxvalue
             ReceiveTimeout = timespan.maxvalue
             MaxReceivedMessageSize = int.maxvalue
             MaxBufferSize = int.maxvalue

       If net.tcp:
           NetTcpBinding
              Security.Mode = none
              ReliableSession.Enabled = false
              MaxReceivedMessageSize = int.maxvalue
              MaxBufferSize = int.maxvalue

Customizing configuration

You can customize both client and server Push configuration in 2 ways:

  1. Via custom implementations of ServiceHostEvents (for the server) and ServiceProxyEvents (for the client). These classes allow you to customize the configuration of endpoints as they're created, and the configuration of the proxy (client) or service prior to usage.
  2. Via configuration settings for the ServiceModel.  See the sample files in the " Deployment\Sample Configuration Files" folder installed with the DevForce samples.  Specifically the ServiceReferences.ClientConfig in the Silverlight subfolder, and the web.config in the "IIS Files" subfolder.

More information is available in the readme.txt available with each sample.

Prerequisites

  • If using the Silverlight sample you will also need to reference several assemblies in the Silverlight 4 SDK.  The Silverlight sample uses the PollingDuplexHttpBinding available in the SDK.


Created by DevForce on July 15, 2010 17:25

This wiki is licensed under a Creative Commons 2.0 license. XWiki Enterprise 3.2 - Documentation. Copyright © 2015 IdeaBlade