TJ's Blog TJ's Blog on .NET and Programming

User eXperience – A Mobile Journey into the Human Mind

May 7

My presentation at Mobile Camp Oz on 7 May, 2011. Borrowing ideas from the User eXperience presentation but with a mobile twist.

Note: Slideshare does not support the animation at the beginning, so this is without that animation.

Returning Big Datasets with WCF RIA Services

March 23

If for whatever reason you need to return a very big set of data using WCF RIA Services, you will see that, you will quickly run into major roadblocks.

The first roadblock is the error message you will get and you will get an error message. It will simply say “Not Found” or something to that effect, and you may be left scratching your head.

To make matters worse, you then use a .Take(500) on the Domain Service method and your data returns.

Now you are more confused.

What I will tell from here on applies to Silverlight project I was working on and therefore everything I say will be in that context using the Business Template. However, everything should be applicable to any project that you use WCF RIA Services.

WCF RIA Services have a limitation on how much data the domain service returns. And unfortunately there is no obvious place to configure this. And there are no samples on the web. They usually concentrate on bits and pieces but not the whole picture.

Once you know what to do, actually it’s all pretty easy and straight forward.

In the web.config, you have a section called <system.serviceModel>. Just go and add this piece of code, under that:

Code
<services>
      <service name="YOUR_PROJECTNAME.Web.YOUR_DOMAINSERVICE" behaviorConfiguration="YOUR_PROJECTNAME-Web-YOUR_DOMAINSERVICE" />
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="YOUR_PROJECTNAME-Web-YOUR_DOMAINSERVICE">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

Pay attention to dots “.” and dashes “-“ in the code above as they are important.

And then… well, that’s it. What you’re doing is basically getting the end point to your web service, which is generated at runtime, and adjusting its maxItemsInObjectGraph property. The value we use is the highest for integer.

Using Web Forms with MVC 3

February 19

There are bunch of reasons why you would want to mix up web forms with Razor views; but for me it is usually the simple fact that I love Telerik’s asp.net ajax controls and want to use those rich controls when appropriate.

However, as you may already know, this is not so easy to do. One approach is to have a separate master page for the aspx pages and happily code alongside your razor views.

Another, but more trickier approach is to code a bit more and use the same master page for both Web Forms and Razor views.

Scott Hanselman talks about both of these approaches here.

Although I like the second approach a lot, I wanted a simpler approach. So, I ended up having the aspx page hosted in an iframe. This really worked beautifully, with all the functionality of the aspx page retained. This was sufficient for my needs, so try this one and if it works, then excellent – no need to maintain a .master page.

Here is the razor view code:

Code
  1. <iframe src="path to your aspx page" frameborder="0" width="100%" id="frame" marginheight="0"></iframe>

Sydney .NET User Group Links

February 16

Here are the links from the User Group today (16 Feb 2010)

Microsoft and Nokia working together in mobile world: http://gigaom.com/mobile/are-nokia-and-microsoft-hoping-two-wrongs-make-a-right/

RedGate makes .net reflector fee-based: http://www.red-gate.com/products/dotnet-development/reflector/announcement

JQuery 1.5 released: http://www.webdeveloperjuice.com/2011/02/12/whats-new-in-jquery-1-5-explained/

Office 365: http://www.talkingoffice365.com/

Dev vs. Dev. Microsoft mobile App Competition: http://tinyurl.com/4ruup3y

Moonlight Preview 4 released: http://www.novell.com/news/press/2011/2/moonlight-4-preview-now-available.html

Web Development with Asp.net links from Microsoft: http://msdn.microsoft.com/en-us/rampup/dd861531.aspx

Microsoft virtual labs for mobile development: http://msdn.microsoft.com/en-us/aa740452

VS Live 2011 Las Vegas: http://www.vslive.com/LV

Microsoft Australia visual studio testing road show: http://www.microsoft.com/australia/visualstudio/testing-roadshow

Free Silverlight controls from MindScape: http://www.mindscapehq.com/products/silverlightelements/free-controls

Microsoft Web Farm Framework released: http://weblogs.asp.net/scottgu/archive/2011/01/20/microsoft-web-farm-framework-2-0.aspx

Microsoft released MVC3, IIS Express and SQLCE 4 and bunch of other apps: http://weblogs.asp.net/scottgu/archive/2011/01/13/announcing-release-of-asp-net-mvc-3-iis-express-sql-ce-4-web-farm-framework-orchard-webmatrix.aspx

NuGet 1.1 released: http://weblogs.asp.net/scottgu/archive/2011/02/14/nuget-1-1-released.aspx

You can use NuGet in WPF and Silverlight too. Here is how: http://10rem.net/blog/2011/02/10/nuget-for-wpf-and-silverlight-developers

Mobile CampOz 2011: http://mobilecampoz.com/

Composite One Open Source CMS: http://www.composite.net/C1.aspx

NetComm’s awesome mobile Wi-Fi router: http://www.netcomm.com.au/netcomm-products/3g-mobile-broadband/3g24w

Web Camps: http://www.webcamps.ms/upcoming-web-camps.aspx

Hire a SIM Card while in the USA that is good anywhere in the world: http://www.iphonetrip.com/

User eXperience

January 20

Last night I gave a presentation on User eXperience at the Sydney .NET User Group.

MonoTouch 101

January 20

I gave a presentation on MonoTouch and how to build iPhone applications using C# in November 2010 and December 2010 at the Sydney .NET User Group and Canberra .NET User Group.

Opening a New Chrome Page In Silverlight

October 20

Silverlight works awesome in Internet Explorer when it comes to opening a link in a new browser window. Sadly, this is not the case when it comes to other browsers, but there is hope.

Create a new Silverlight Application in Visual Studio 2010. And add a button to your page. Let’s try to navigate to http://www.silverlight.net address when we click on this button.

Add this to the code behind of this button by double clicking the button (we will use code behind for demonstration purposes):

 

Code
private void button1_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            HtmlPage.Window.Navigate(new Uri("http://www.silverlight.net", UriKind.RelativeOrAbsolute), "_blank");

        }

And then start your project in Chrome; click the button and you will see that it will not do anything. Open the same page in Internet Explorer, it will work as advertised.

The trick is to use the Hyperlink Button here. Now, go ahead and add a new hyperlink button to your page. Now same kind of code behind for the hyperlink button click:

 

Code
private void hyperlinkButton1_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            this.hyperlinkButton1.TargetName = "_blank";
            this.hyperlinkButton1.NavigateUri = new Uri("http://www.silverlight.net/");
        }

Of course you can set the hyperlink button properties on the properties page as well, if you know the hyperlink in advance.

If you search for this problem, you will see that there is a JavaScript solution as well; however, I could not get that to work on my projects.

 

Unable to Debug Silverlight

September 17

Well, after a long time due t a project I am back.

Today, I came across this error when I was trying to debug my Silverlight application:

image

Somehow, I must have visited some site that has some other version of Silverlight and it must have overwritten my version – as this application was working yesterday.

This really should not have happened no matter where I visited. The developer version of Silverlight should have been kept.

Second, the solution is easier than I thought. Just head to http://go.microsoft.com/fwlink/?LinkID=188039 and you will find the Silverlight developer Runtime installer there. Just follow the prompts and you can now happily debug your Silverlight applications again.

Data Pager Load Error

May 26

If you are using a data pager on your view in a Silverlight application, when you run it and try to click the next page button couple of times you may get an error like this:

DataPager Error

This is because the query is stateless and without an order, it is not possible to do a valid skip.

So, for the datapager to work correctly, you need to provide an “order by” to your returned resultset.

Assuming that you are using DomainServices, go to your domain service and find the Get() method. This could be GetCustomers, GetOrders etc.

The code you will see is something like below:

 public  IQueryable <Customers > GetCustomers()
 {
     return  this .ObjectContext.Customers;
 }

Change this to:

 public  IQueryable <Customers > GetCustomers()
 {
     return  this .ObjectContext.Customers.OrderBy(c => c.CustomerID);
 }

And you have your data pager working nicely.

Firefox Cache Problem When Debugging Silverlight Apps

May 25

On a previous article, we looked at how we can change the default browser that we use to run our Silverlight application in Visual Studio.

You can definitely choose Firefox as your default browser, however, you need to be aware that if you close the tab or the browser while your Silverlight application is running, your debugging session will not end. The same applies to when you end your debugging sessions from Visual Studio – you will see that the tab or the browser does not close. You do get this behavior for free in Internet Explorer.

But the biggest difference between debugging a Silverlight application in Firefox and Internet Explorer is the cache. With Firefox, sooner or later you will see that the browser will not be loading the latest build every time you run your app. Firefox keeps feeding you the cached version. Of course, you can put a version number to you xap files but as you can imagine this gets very inefficient when you are developing a Silverlight application.

There is a plug-in in Firefox, called Web Developer (http://chrispederick.com/work/web-developer/). After installing this plug in, just disable the cache by right clicking on a web page and choosing Disable >> Cache from the menu and you should be good to go.

Figure: Using Disable menu option in Firefox plug in Web Developer.

Another option you have is getting Firefox in Private Browsing mode.  This mode, does not record anything about your session, so it should load the latest build of your Silverlight application. You can start a private session from Tools >> Start Private Session.

Figure: Starting a private session in Firefox

Internet Explorer, however, does not seem to have this problem.

« Older Entries