
Back to Blog index.
Developer.com has today published my latest article about Windows Live Services, a set of web-based services accessible both interactively and from code with an HTTP (and sometimes SOAP) interface.
The article shows how to use the Live Search using C# and the SOAP interface, then uses an interactive Virtual Earth map, and finally shows how to use the Presence Service.
Enjoy reading!
If you have studied the new features in Internet Explorer 8, you know that one of them is Web Slices.
Web Slices allow parts of a web site to marked as an updateable slice, which you can then add as a favorite to our IE8 browser. Whenever the slice updates on the origin server, IE8 catches that up, and shows it to the user. RSS, sort of.
Now, despite the documentation on MSDN and elsewhere, it's actually quite hard to find real-world examples of the technology. Luckily, there's at least one such site, called LiveSlices. Check it out.
Interested in learning and teaching in general? Microsoft has announced a new digital learning platform called Semblio. The idea is that you can use .NET and WPF technologies to author interactive learning material and share it with students.
If this sounds interesting, be sure to check out the short video tutorial on the site, and then proceed to download the SDK.
If you are building web applications with Visual Studio and ASP.NET Dynamic Data, you know that the default location for the page and field templates and content images is a virtual folder named "/DynamicData". This is good for simple web sites, but if you want to integrate your Dynamic Data application into an existing ASP.NET web application, you need to change this location.
As you might guess, you cannot simple rename this folder as this wouldn't work. Instead, you have to set a property called DynamicDataFolderVirtualPath in Global.asax code-behind file, and then rename your folder. This property is part of the MetaModel object that is automatically created for you in the RegisterRoutes method, which is part of the template code. Here's an example:
MetaModel model = new MetaModel(); model.RegisterContext(...); model.DynamicDataFolderVirtualPath = "~/MyFolderName/DynamicData";
MSDN also features a howto article about this.
If you have used LINQ queries previously, you are probably happy to use the forthcoming Parallel LINQ or PLINQ that is part of Visual Studio 2010. It's great to have an "automatically" parallel version of your queries, so that you can maximize your use of the resources your multi-core desktop processor has. However, PLINQ isn't an automatic salvation to all your performance problems, simply because using PLINQ can transfer the work from the database server to your client.
Of course, this all depends on what you are after. But let's have a concrete example. Assume you are using SQL Server as your database, to which you then execute the following LINQ query:
NorthwindDataClassesDataContext cntx =
new NorthwindDataClassesDataContext();
var cust = from c in cntx.Customers
where c.Country == "USA"
select c;
As you can guess, this query fetches all the customer records that have the country value of "USA". Now, behind the scenes, LINQ to SQL executes the following SQL statement to get the records (easy to see using the SQL Server tracing utility):
exec sp_executesql N'SELECT [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Country], [t0].[Phone], [t0].[Fax] FROM [dbo].[Customers] AS [t0] WHERE [t0].[Country] = @p0', N'@p0 nvarchar(3)',@p0=N'USA'
As you can see, the filtering for the customers occurs on the database server.
Next, let's change the query to use PLINQ by simply adding the ".AsParallel()" method call after the customer table object in Visual Studio 2010:

This is the new C# code for the PLINQ query:
var cust = from c in cntx.Customers.AsParallel()
where c.Country == "USA"
select c;
But how would you guess PLINQ would execute the SQL query if the aim is to enable the client computer to use multiple threads to process the results? Well, to solution is to do the country filtering on the client. In deed, this is reflected in the SQL statement, which now becomes:
SELECT [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Country], [t0].[Phone], [t0].[Fax] FROM [dbo].[Customers] AS [t0]
As you can see, the SQL query changes quite a bit. The results are naturally the same, but the processing (filtering) changes from the server to the client. If you have 100 records in the customers table, you won't probably see much difference in processing time, network utilization or memory usage. But if you had 1,000,000 records, things would change.
This is not necessarily a bad thing, but you have to understand the consequences of using PLINQ. Using it should be decision you make after judging the effects.
Earlier this week, Microsoft announced that the ASP.NET MVC framework is now ready. You can download the RTM version from Microsoft Downloads.
For more information about the MVC framework and how to use it, visit the official ASP.NET MVC page.
Happy coding!
Microsoft today announced that Internet Explorer 8 (IE8) web browser is now ready and available from their downloads. The browser didn't spend a long time in the Release Candidate mode, meaning that the product was already quite finished at that time.
New features include web accelerators (select text and see options pop up), web slices (automatically follow changes in different sites), compatibility with latest standards, and privacy enhancements among others.
To get the latest version, visit the dedicated IE8 page.
Microsoft's web-oriented developer conference, Mix09, is again starting in Las Vegas. This year, the topics range from Silverlight 3 beta to Expression tools and everything between. Here's a quick highlight of things that are new:
To view the latest content, visit the Mix09 web site.
I recently had the need the add more features into one testing server I have. The server is running SQL Server 2008 Standard, but I needed features only available in the Enterprise Edition. Sounds simple enough, but I noticed that it wasn't as easy as just putting the Enterprise DVD on the drive and then doing an upgrade.
That is, since I already had an instance of Standard Edition installed, the Enterprise Edition setup only offered to install another instance of Standard Edition. I think I could have entered the product key for Enterprise Edition during the setup to get the setup install Enterprise instance directly, but as the MSDN medias re pre-pidded (have the serial numbers ready), I never took a record of the different keys. Until now, that is.
In the end, I ended removing the old Standard installation completely, and then re-installing Enterprise. Took a while, but sometimes these things do. Of course, all this sounded like a sub-optimal solution. So, if you know a better solution (now I have the Enterprise product key), don't hesitate to let me know. Thanks!
So far, Windows Azure only had useful, but still quite difficult-to-program data storage and query support—many more developers are familiar with for example SQL Server data access standards than the Azure ones. No, I'm not saying that Azure's previous data support was bad, it was just different.
Luckily, times are changing as Microsoft has just announced that they are planning, more or less, to host SQL Server on the cloud. Well, it's not SQL Server on Azure 100%, but still you get really close: the aim is to have SQL Server's TDS network protocol to access Azure databases seamlessly on the cloud. Whohoo!
In fact, they are planning to support Visual Studio and ADO.NET compatibility (I wonder what the server addresses will be like), and the most important features there like tables, views, stored procedures, triggers and indexes. Sounds like a plan to me.
64-bit PC computers have existed for years, but the fact is that most users still work with 32-bit systems, and we have to wait a couple of years for the doubling of bits to become mainstream. Personally, I believe that ordinary people will first notice that they need a 64-bit system once they start needing more than 4 GB of memory, but that's a topic for another post.
Now, as a .NET developer, you are quite effectively guarded from the number of bits in the operating system and the processor. But even so, you must know how to detect the “bitness" of the operating system under which your application is running. Similarly, you have to be aware of the options of compiling your applications for 32-bit and 64-bit platforms.
The first thing to remember is that a regular 32-bit Windows system cannot run 64-bit applications, but a 64-bit Windows can run both 32-bit and 64-bit applications. Now, if you compile your C# application with Visual Studio by default, it will function as a 32-bit application on a 32-bit Windows box, and as a 64-bit application on a 64-bit application.
However, you can also control the number of bits your application supports. In Visual Studio's project properties, you can find a setting called “Platform target" under the Build tab:

The default value for this setting is “Any CPU", which works as described above. By selecting “x86", you can force your application to always be a 32-bit application, or by selecting “x64", to always be a 64-bit application. Of course, if you compile your application to be a 64-bit application and you try to run it on a 32-bit operating system, the results can be like this:

In text, the error message says:
The version of this file is not compatible with the version of Windows you're running. Check your computer's system information to see whether you need an x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher.
As you can see, the Platform target setting in Visual Studio is pretty straightforward and easy to understand. But how would you detect the current platform in your code, and the specified platform target in code? Luckily, this is quite easy as well, and I'll share some code as well.
Firstly, you might want to detect the bit depth of the current operating system. As you might guess, there are multiple ways to do that, but one of the simplest ways to do this check is to see if the registry key “HKEY_LOCAL_MACHINE\Software\Wow6432Node" exists. If it does, it's pretty good indication the system is (recent) a 64-bit Windows. Here's the quick C# code to detect this:
using Microsoft.Win32;
...
StringBuilder builder = new StringBuilder();
builder.Append("Wow64 key: Does ");
RegistryKey wow64Key = Registry.LocalMachine.OpenSubKey(
"Software\\Wow6432Node", false);
if (wow64Key == null) builder.Append("NOT ");
else wow64Key.Close();
builder.AppendLine("exist");
MessageBox.Show(builder.ToString());
Then, how could you detect the chosen number of bits of your executable? If we again take the straightforward route, then checking the size of the IntPtr structure works well and is fast. If the size is 4 bytes, then you are running your code in a 32-bit application and if 8, then it's a 64-bit application:
builder.AppendLine("IntPtr size: " + IntPtr.Size.ToString());
If you want more proof, then Windows API supports a function called IsWow64Process. The problem with this function is, however, that it requires Windows XP SP2 or Windows Server 2003 at least. This function returns true if your application is running in WOW64 mode (WOW64 stands for “Windows On Windows 64" and allows 32-bit applications to run on a 64-bit operating system) and false if not. So, if you specify your application to be a 32-bit application with the Platform target setting set to “x86" and then run your application on a 64-bit computer, then IsWow64Process will return true.
Here's a short C# code snippet to show how you can use the API function:
using System.Runtime.InteropServices;
using System.Diagnostics;
...
[DllImport("kernel32.dll", SetLastError = true,
CallingConvention = CallingConvention.Winapi)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsWow64Process(
[In] IntPtr hProcess,
[Out] out bool wow64Process);
...
Process p = Process.GetCurrentProcess();
IntPtr handle = p.Handle;
bool isWow64 = false;
if (IsWow64Process(handle, out isWow64))
{
builder.AppendLine("IsWow64Process: " +
(isWow64 ? "Yes" : "No"));
}
else
{
builder.AppendLine("IsWow64Process: Call failed");
}
I compiled the following table to help you see how this works in practice:
| Windows OS bits | Platform target setting (application bits) | IntPtr.Size | IsWow64Process return value |
| 32-bit | Any CPU | 4 | false |
| 32-bit | x86 | 4 | false |
| 32-bit | x64 | (app won't run) | (app won't run) |
| 64-bit | Any CPU | 8 | false |
| 64-bit | x86 | 4 | true |
| 64-bit | x64 | 8 | false |
Remember, the tips shown here to check the "bitness" might not be the official ones, but work reasonably well most of the time.
Good luck!
Keywords: Visual Studio Platform Target, 32-bit and 64-bit applications, how to detect number of bits in the operating system, how to check is operating system is 64-bit.
In addition for writing technical articles about software development for over ten years, I've been recently asked to send in some screencasts about currently "hot" development topics. Of course, web development with latest technologies is always in, so I decided to author a 101 style of topic about ASP.NET Dynamic Data.
The screencast is available for free and without registration on Internet.com (with links to it on Developer.com), and it was published on March 5th. The cast runs for about six minutes.
Enjoy!
Two days of whirl are over as TechDays 2009 just passed by. Tons of new information is again waiting to be digested, so there's plenty of new things to learn this March. I also had an ASP.NET session there about Dynamic Data, which was an interesting topic to the audience, if the number of questions received is anything to judge by.
I promised to share my presentation's two sample applications, and here they are:
Feel free to download there and use to your liking. Let me know if you use these somewhere or need additional help with custom development, I'm here to help as always.
Thanks for Microsoft for holding this great event at the Helsinki Fair Center, and thanks for the MVP thumbs-up on stage!
Are you using Microsoft's Expression products for graphical design or WPF/Silverlight application design or development? If yes, then you might be interested in a newish web site called Microsoft Expression Community, which is available at expression.microsoft.com.
The site contains a user-generated portion, but also an MSDN like library about technical details of the Expression products like Expression Web, Expression Blend and Expression Design. So if you are looking for information about how to use these applications and take them to the max, this site is a great place to start.
Welcome, March! Earlier this week, I got a question regarding .NET 2.0 (or later) WinForms applications and Code Access Security or CAS. If you are familiar with CAS, then you know that you can use the .NET Framework 2.0 Configuration utility (part of Administrative Tools) to set up security for your applications.

However, the question I got was that where can this tool be found from the client computers? The answer is that unlike the older .NET 1.1 configuration tool, the .NET config tool for version 2.0 and later is not part of the .NET Runtime, and instead only comes with the SDK kit. That said, you could of course install the SDK on a client computer and then use the config tool, but if your only reason to install the SDK is to get the tool, I have a better alternative.
Firstly, you can use the command-line tool called caspol.exe. This comes with the framework, so it is available on all computers which have .NET 2.0 installed. By running a command like this you could add machine-wide full trust to a given executable, for instance:
caspol -m -af C:\Apps\MyApp.exe
The second options is to use the configuration utility to set the correct policies on your development machine, and then create an MSI installer package from those settings. This can be done by right-clicking the Runtime Security Policy node (see the above image), and then choosing the command Create Deployment Package. This process is detailed in the Microsoft KnowledgeBase (KB) article 931867.
› Blog Archive