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

.NET Framework 4 vs .NET Framework 4 Client Profile

In .NET Framework 4 we have introduced a streamlined subset and more compact version of the .NET Framework called the Microsoft .NET Framework 4 Client Profile (aka NET4 Client Profile). The Microsoft .NET Framework 4 which is the Full Framework (aka NET4 Full) still exists and it is a superset of the Client Profile.

What are the reasons for a Client Profile?

Although the NET4 Client Profile is smaller and faster to install compared to the NET4 Full Framework (NET4 is 7-8MB smaller in size than the Full Framework), the main reasons are not just better deployment size/time but also:

  • Reduce the Framework deployment failures.
  • By keeping ASP.Net and other components (that are mostly needed for servers) out of the Client Profile, we can reduce the attack surface and the number of future servicing events which may be caused by server component (such as ASP.Net) and are not needed for desktop scenarios.
  • Making NET4 Client Profile available on Windows Update will make sure that most desktop machines will include NET4 Client Profile over time and apps that target the Client Profile will not need to carry or install the Framework which will improve the overall deployment experience.
  • Enable us to add features and grow the size of overall Framework in future versions but still have a smaller core.
When to use NET4 Client Profile and when to use NET4 Full Framework?

NET4 Client Profile:

Always target NET4 Client Profile for all your client desktop applications (including Windows Forms and WPF apps).

NET4 Full framework:
Target NET4 Full only if the features or assemblies that your app need are not included in the Client Profile. This includes:
  • If you are building Server apps. Such as:
    1) ASP.Net apps
    2) Server-side ASMX based web services
  • If you use legacy client scenarios. Such as:
    1) Use System.Data.OracleClient.dll which is deprecated in NET4 and not included in the Client Profile.
    2) Use legacy Windows Workflow Foundation 3.0 or 3.5 (WF3.0 , WF3.5)
  • If you targeting developer scenarios and need tool such as MSBuild or need access to design assemblies such as System.Design.dll

    Reference Links:
    1) http://blogs.msdn.com/b/jgoldb/archive/2010/04/12/what-s-new-in-net-framework-4-client-profile-rtm.aspx
     

Read More

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.Open();
            pushChannel.BindToShellToast();
      }
      else
       {
            System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
            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.

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

            });
        }


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

2)
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