+91 20 24210201/301 info@genex.co.in

Push notifications for Windows Phone 8

It is very easy to send push notification on Windows Phone 8. Just doing few steps.

Creating a push client to receive toast notifications:
1) Create a new Windows Phone 8 app.

2) Name the project GenexToastClient.

3) Add the following using directives to the top of the MainPage.xaml.cs file.

  using Microsoft.Phone.Notification;

3) Add following code in MainPage.xaml.cs file.

 public MainPage()
      HttpNotificationChannel pushChannel;
      string channelName = "ToastDemo";
      pushChannel = HttpNotificationChannel.Find(channelName);
     if (pushChannel == null)
            pushChannel = new HttpNotificationChannel(channelName);
            pushChannel.ChannelUriUpdated += new EventHandler(PushChannel_ChannelUriUpdated);
            pushChannel.ChannelUriUpdated += new EventHandler(PushChannel_ChannelUriUpdated);
            MessageBox.Show(String.Format("Channel Uri is {0}", pushChannel.ChannelUri.ToString()));

    void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)

            Dispatcher.BeginInvoke(() =>
                //Normally, the URI would be passed back to your web service at this point.

                MessageBox.Show(String.Format("Channel Uri is {0}", e.ChannelUri.ToString()));


Sending a Toast Notification:
1) Create new ASP.Net web application

Add one button on default.aspx page  and put the following code in side the button_onclick event
//Run GenexToastClient app. Windows Phone Emulator initializes, and then the app starts. After a moment or two,
//the app should display a message with the push channel URI.  This URI also will be displayed in the Visual Studio debugger Output window.
//copy this URI and pass to ChannelUri variable in following code.

string ChannelUri = "http://db3.notify.live.net/throttledthirdparty/01.00/AQGshG_QxJs2QIO1OID6wTLxAgAAAAADAQAAAAQUZm52OkJCMjg1QTg1QkZDMkUxREQFBkVVTk8wMQ";

                HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(ChannelUri);
                sendNotificationRequest.Method = "POST";


              // Set the notification payload to send.
                byte[] notificationMessage = Encoding.Default.GetBytes(toastMessage);

                // Set the web request content length.
                sendNotificationRequest.ContentLength = notificationMessage.Length;
                sendNotificationRequest.ContentType = "text/xml";
                sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "toast");
                sendNotificationRequest.Headers.Add("X-NotificationClass", "2");

                using (Stream requestStream = sendNotificationRequest.GetRequestStream())
                    requestStream.Write(notificationMessage, 0, notificationMessage.Length);

                // Send the notification and get the response.
                HttpWebResponse response = (HttpWebResponse)sendNotificationRequest.GetResponse();
                string notificationStatus = response.Headers["X-NotificationStatus"];
                string notificationChannelStatus = response.Headers["X-SubscriptionStatus"];
                string deviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"];

3) Run web app and  Press the button on default.aspx page. you will get the notification on your windows phone.

Happy Coding   smiley

Read More

Getting your BackBone HTML5 app ready (compatible) for HTML4 browsers

Building single-page web apps or complicated user interfaces will get extremely difficult by simply using jquery. The problem is standard JavaScript libraries are great at what they do and without realizing it you can build an entire application without any formal structure. You will with ease turn your application into a nested pile of jquery callbacks, all tied to concrete DOM elements. As I said jquery can build an entire application without any formal structure and hence we need something with good structural format, which incorporates with full functional jquery, HTML5 and CSS3.
The web is currently trending such that all data/content will be exposed through an API. This is because the browser is no longer the only client; we now have mobile devices, tablet devices, Google Goggles and electronic fridges etc.

Backbone.js gives structure to web applications, models with key-value binding, collections with a rich API of enumerable functions, views with declarative event handling. Backbone.js enforces that communication to the server should be done entirely through a RESTful API. Backbone is an incredibly small library for the amount of functionality and structure it gives you. It is essentially MVC for the client and allows you to make your code modular.
And it works great in modern browsers. So what’s the problem area then? The problem arises when you wanted same application with all the features working on HTML4 browsers. The HTML4 browsers don’t support HTML5 behavior like history, pushstate and requirestate that require for navigation purpose in Backbone.js instead the HTML4 browsers supports hash fragments navigation for pure jquery.
The modern browsers support properties like crossDomain in ajax call to support request across the different domains, while HTML4 browsers supports conventional ajax call. The most vulnerable problem with HTML4 browsers is after first ajax call it caches all the request and afterward it fetches from cache, which gives impression that the application not saving or updating the values.
Backbone Router provides methods for routing client-side pages, and connecting them to actions and events. Backbone Router with History API uses standard URLs (/page) instead of traditional hash fragments (#page). During page load, after your application has finished creating all of its routers, be sure to call Backbone.history.start(), or Backbone.history.start({pushState: true}) to route the initial URL.
Following is the workaround you can try for getting your BackBone app ready for HTML4 browsers:
·         The History API the pushState value should be false.
·         Include Modernizr a JavaScript library that detects HTML5 and CSS3 features in the browser.
·         Check whether the browser supports History API instead check whether the browser supports the HTML5 properties and here is the example how to achieve the same.
//when your application starts up
Backbone.history.start({ pushState: Modernizr.history });
if(!Modernizr.history) {
    var rootLength = Backbone.history.options.root.length;
    var fragment = window.location.pathname.substr(rootLength);
    Backbone.history.navigate(fragment, { trigger: true });
} else {
·         If you are using ajax call in the application, should not use the crossDomain property of ajax, it will break your request in the browsers which don’t support HTML5.
·         Check whether any broken tags and appropriate function completion. Most common mistake is trailing commas after callback function and property declaration.
·         The most common problem of the browsers which don’t support HTML5 is ajax cache. The browser caches the request and response data for the first time and provides the response from cache thereafter. You should manually turn the cache off by setting the property cache:false to ajax call.
·         If you are using the HTML5 tags in the application, you should include html5shiv.js JavaScript library that enables the HTML5 basic tags for the browsers which don’t support HTML5.
·         For proper working of CSS classes, you can use IE filter and CSS hack attributes in CSS class. The IE filter attributes are mainly helpful for gradient and opacity effect and the CSS hack attributes helps to adjust auto property which is not supported by HTML4 browsers.

Read More

Implementation of Aspect oriented programming

- In spring Aspect enables the modularization of cross cutting concerns.
- Using Aspect code related to implement cross cutting concerns remains outside the normal program structure.
- One of the ways to implement Aspect is by annotating regular classes by @Aspect.
Terms in AOP:
1) Join point: Represents method execution.
2) Pointcut: Tells what method is invoked.
3) Advice: Action taken by advice at particular join point.
Types of Advices:
a) Before advice: advice that executes before join point.
b) After returning advice: advice that executes after join point completes normally.
c) After throwing advice: advice that executes if method exists by throwing exception.
d) After advice: advice that executes in normal and exceptional exits.
e) Around advice: advice surrounds the join point.
Configurations to implement AOP:
(Add in applicationcontext.xml)
- Component scanning of package containing class annoted with @Aspect
  (eg. )
Jars :
- aspectjweaver-1.6.12.jar
- aspectjrt-1.6.12.jar
- spring-aop-3.1.2.RELEASE.jar
Examples :
1) After returning aspect:
package com.example.aspect;
 public class AfterReturningExample {
public void executeMethod() {
@AfterReturning(pointcut = "executeMethod()", returning = "object")
public void afterReturningMethod(Object object) {
  // Implementation
2) After Aspect
package com.example.aspect;
 public class AfterAspectExample {
public void executeMethod() {
public void afterMethod() {
  // Implementation

3)  Before Aspect
package com.example.aspect;
 public class BeforeAspectExample {
public void executeMethod() {
@Before("executeMethod()  &&  args(object)")
public void beforeMethod(Object object) {
  // Implementation
4) After throwing Aspect
package com.example.aspect;
 public class AfterThrowingAspectExample {
@AfterThrowing(pointcut = "execution(com.example.myapp.SystemArchitecture.businessService())",
 throwing = "exception")
 public void afterThrowing(JoinPoint joinPoint, Object exception) {
5) Around Aspect
package com.example.aspect;
 public class AroundAspectExample {
 public Object aroundMethod(ProceedingJoinPoint pjp) throws Throwable {
                   //before Implementation
                   Object retVal = pjp.proceed();
                   // after implementation
                   return retVal;

Read More

WCF Project Deployment Considerations

In this post I am going to explain the problem we have faced during the deployment process of WCF services based project.
The project Application Pool stops/shut down regularly and can’t access the REST services from UI.
Project Description:
The project has WCF rest services to communicate with UI layer and data layer.
1. The application pool must operate under NetworkService account (i.e. Process Model => Identity = NetworkService). 
The Default App pool had been set to run as IWAM_SOMEUSER and that user didn’t have permissions to access the WCF service files, but NetworkService did.
2. The Idle Time-out should be set to under Process Model tab.
Idle Time-out is the amount of time in minutes a worker process will remain idle before it shuts down. The default value is set to 20 minutes. The value 0 means the worker process will never shut down as long as user manually does.

Read More

The Digital Enterprise Revolution: Some Subtle Implications

In my last post I presented our Digital Revolution infographic. As I was pondering some of the data points it covers, I got to thinking about their implications for the fields of marketing and commerce, and their enabling technologies. Most of the obvious implications have been written about at length elsewhere, but today I’d like to take a look at some of the not-so-obvious ones:
New mobile customers: Everyone talks about the mobile web surpassing the fixed web, but it pays to look at the customers who are driving this. According to the International Telecommunications Union, this year mobile broadband subscriptions in developing countries surpassed subscriptions in developed countries. Beyond that, there’s lots more headroom for growth and the mobile web is cheaper and easier to access than the fixed web in the developing world. The implication? While it’s critical for global brands to have a mobile strategy, it’s equally critical that that strategy comprehend the huge opportunity web-enabled phones are bringing to developing countries, and the challenges that accompany that opportunity: supporting price points that are affordable to these new customers, processing their payments, even the packaging and supply chain strategies required to ensure they get the right product at the right place and time.
Cross-channel table stakes: Nearly everyone who can shop in the US is now shopping online, and while just about every major US retailer is there to sell to them, there are plenty of leading retailers and brands that still aren’t taking any form of cross-channel seriously. With traditionally online-only retailers like Amazon and eBay (and non-retailers like google) quickly moving to provide same-day delivery, ignoring cross-channel is suicide. Single channel retailers who don’t quickly take the big leap into cross-channel (or better yet, omni-channel) will have to be satisfied with becoming niche players -- or worse, showrooms for competitors.

Read More