Wednesday, May 2, 2012

Metro App invoking WCF service , Simples WCF, Metro App Consuming WCF.


Metro App invoking WCF service





Hi All,



I created the very basic Metro App “Split application”. The post is can be segregated in two halves. The first one explains about the default coding which comes automatically when developer choose the template “SplitApplication” from visual Studio 2011, and second half talks about customization in data part of UI.

The first half of Story

 The default application creates data source in-memory and displays that. I consumed web service and created navigation page.

The Key learning’s are –

·         The source which is going to be binding either to dataGrid or ListView should be ObservabaleCollection

·         In GridView to make item clickable “IsItemClickEnabled” must be true.

·         Get ready to code async way.



Below is the diagram for default source code and application given –

The Flow of events for the sample split application is  ->

·         App.Xaml.cs loads the Items.xaml .

·         The item.xaml is bind to SourceData, which provides the ObservableCollection of Data.

·         GridView and ListView are in item.xaml are bind to ObservableCollections of SampleData. [The controls in xaml are using resource which are defined in StandarStyle.xaml inside common folder. The standard250X250Itemtemplate defines title and subtitle by default, modification in these resource  will have effect in display of controls.]

·         The GridView in item.xaml has IsItemClicabk true and event receiver is attached to “ItemClick’ which navigates and load to SplitPage.

My Experiment with custom WCFService

The second half of Story



Create one WCF service, which reads data from xml file and returns it.

Two public methods – GetAllBooks() and GetBookByID()

Create one page – myItems.

Goto App.xaml  write - _rootFrame.Navigate(typeof(myItems));



Add reference to custom web service.

Goto myItems.xaml.

Open “OnNaviagte”;

Bind your collection which returns ObservableCollection of object. [This will make changes to UI hence it must be in different thread] so the code is like –

Protected override void OnNavigatedTo(NavigationEventArgs e)

{

This.DefaultViewModel[“Items”] = e.Parameter;

BookStoreService.Service1Client  svr = new BookStoreService.Service1Client();

Svr.OpenAsync();

System.Threaading.Tasks.Task> result = svr.GetAllBookAsync();

Dispatcher.Invoke(Windows.UI.Core.CoreDispatcherPriority.Normal,(obj,invokeArgs) =>

{

itemGridView.ItemsSource = result.Result;

},this.null);

}

Go to Item_Click event. { this.Frame.Navigate(typeof(mySplitPage),e.Clickedtem));

From this code you got it J Add another page of type split and name it to myitemDetail.

 Do F5..You are done. !!

Friday, April 20, 2012

HTML5, Offline, AppCache, .cache = text/cahce-manifest


Hi,

Since I started on HTML5, metro and win8. The interesting things are , IndexDB, offline etc. sadly I couldn't find end-end simple how to get offline working. Below I will explain the simplest How to -

1.      Create asp.net site. Simple site given by Visual Studio.

2.      Think about the resource you want to cache, since this is simplest; I limited myself to cache one image file.

3.      Create a web application in IIS and set virtual directory.

For this web application set the MIME type

            File type = .cache

            Map to – text/cache-manifest

4.      Go to page where is defined.

5.      Modify this with  

6.      Create a file give the same name as defined in manifest=. So I am giving it simple.cache

Simple.cache should look like –



CACHE MANIFEST

CACHE:

<> (with extension and relatives ness>>



Since my cache file is simple.cache, and image file I plan to cache is “mylogo.png” (this is stored in root location for site) so the overall file is



CACHE MANIFEST

CACHE:

mylogo.png



Now run your site. Since the server is available it will run without any problem.

Now stop IIS and rerun site. This time the UI is different as it is coming under offline capability.



Now if you are starting IIS again and want to see original site delete cache from bowser setting. Without this, cached version will be displayed for this simple site.



Enjoy!!




Tuesday, April 17, 2012

Windows 8 - Series 1 (XAML)

Recently I got chance to explore windows8 , windows phone etc. and I felt creating App for windows8 will involve good learning from developer perspective. reasons -
•The thought process about UI has to change, its not conventional UI , navigation being changed drastically.
•The javascript involves good syntax learning and API learning.
•only XAML remains closely same, not exactly same.
The better way to rephrase above is -
•XAML UI developers are Metro style app developers
•Existing XAML assets and knowledge carry forward
•XAML and C++, like peanut butter and chocolate
And Also I figureed out some differences between silverlight and Metro App as well -
Silverlight Application
•Silverlight depends on browser to provide networking code
•Silverlight sends navigation command to browser..
•Silverlight is supported OOB in SharePoint.
•Silverlight needs browser to host application and application interacts with browser first.
•Navigation is done through XAML pages
Metro App
•WinRTrelies on underline system service to provide networking code
•WinRTmanages navigation through system commands
•SharePoint including HTML5 is supported only on latest browser.
•Metro App directly runs on WinRT.
•Navigation is done through type, x:Class.
•XAML for Windows Runtime currently doesn't support custom markup extensions.
Keep Watching – Now I have content to post J

Tuesday, February 28, 2012

Windows Phone SDK7.1 on windows 7 sp1- compatibility issue

hi All,

 
Since I am back to work and hence trying to explore all new. for the same I wanted to explore Windows Phone, hence I saved the vm_web2.exe on hard disk and was trying to install.

 
every time I was getting error - compatibility error goto http://go.microsoft.com/fwlink/?LinkId=143397.

 
I tried -

 
  1. Unsitall Visual studio 2010 professional.
  2. right click on vm_web.exe, properties ->CompatibilityTab.
  3. played with regirtry Entries
 
Nothing worked, finally I landed to download page again and instead of saving to hard disk , I installed from there and every thing is working fine.

 
what a fix :d

 
Save your time and try this as well.

new SPSITE("") error - could find web application at URL

hi All,

I am back Almost after a year :)
When creating console application for sharepoint , today again I got good old error saying could not find the web application. recalled all the thread and now noting down the solution -

Project properties -> target .net framework should be 3.5
and Target  CPU must be "Any" from "Build Tab".

Enjoy coding :)