Learning WPF

As a .net developer that has recently spent over a year helping to design and build a SCSF winforms application, I have been looking to branch out into different techniques and technologies to improve my skill set. With Visual Studio 2010 coming out, the latest support for WPF and a push, by Microsoft, toward its […]

New Embedded Database Support with ASP.NET

New Embedded Database Support with ASP.NET

Earlier this week I blogged about IIS Express, and discussed some of the work we are doing to make ASP.NET development easier from a Web Server perspective.

In today’s blog post I’m going to continue the simplicity theme, and discuss some of the work we are also doing to enable developers to quickly get going with database development.  In particular, I’m pleased to announce that we’ve just completed the engineering work that enables Microsoft’s free SQL Server Compact Edition (SQL CE) database to work within ASP.NET applications.  This enables a light-weight, easy to use, database option that now works great for ASP.NET web development.

Introducing SQL Server Compact Edition 4

SQL CE is a free, embedded, database engine that enables easy database storage.  We will be releasing the first public beta of SQL CE Version 4 very shortly. Version 4 has been designed and tested to work within ASP.NET Web applications.

Works with Existing Data APIs

SQL CE works with existing .NET-based data APIs, and supports a SQL Server compatible query syntax.  This means you can use existing data APIs like ADO.NET, as well as use higher-level ORMs like Entity Framework and NHibernate with SQL CE.  Pretty much any existing data API that supports the ADO.NET provider model will work with it.

This enables you to use the same data programming skills and data APIs you know today.

No Database Installation Required

SQL CE does not require you to run a setup or install a database server in order to use it.  You can now simply copy the SQL CE binaries into the \bin directory of your ASP.NET application, and then your web application can run and use it as a database engine.  No setup or extra security permissions are required for it to run.  You do not need to have an administrator account on the machine.  It just works.

Applications you build can redistribute SQL CE as part of them.  Just copy your web application onto any server and it will work.

Database Files are Stored on Disk

SQL CE stores databases as files on disk (within files with a .sdf file extension). You can store SQL CE database files within the \App_Data folder of your ASP.NET Web application – they do not need to be registered in order to use them within your application. 

The SQL CE database engine then runs in-memory within your application.  When your application shuts down the database is automatically unloaded.

Shared Web Hosting Scenarios Are Now Supported with SQL CE 4

SQL CE 4 can now run in “medium trust” ASP.NET 4 web hosting scenarios – without a hoster having to install anything. Hosters do not need to install SQL CE or do anything to their servers to enable it.

This means you can build an ASP.NET Web application that contains your code, content, and now also a SQL CE database engine and database files – all contained underneath your application directory.  You can now deploy an application like this simply by using FTP to copy it up to an inexpensive shared web hosting account – no extra database deployment step or hoster installation required.

SQL CE will then run within your application at the remote host.  Because it runs in-memory and saves its files to disk you do not need to pay extra for a SQL Server database.

Visual Studio 2010 and Visual Web Developer 2010 Express Support

VS 2010 and Visual Web Developer 2010 Express will add SQL CE 4 tooling support for ASP.NET scenarios in an update we’ll be rolling out in the future.  This will enable you to add SQL CE database files to your ASP.NET projects, use the Visual Studio Server Explorer to create and edit tables in them, and use higher-level designers like Entity Framework (see below) to model and map the database to classes that you can then query and program against using LINQ.

image

This means that in addition to using the same data APIs you know today, you will also be able to easily use the same development tools you already know with SQL CE.

Supports Both Development and Production

SQL CE can be used for both development scenarios and light-usage production usage scenarios.  With the SQL CE 4 release we’ve done the engineering work to ensure that SQL CE won’t crash or deadlock when used in a multi-threaded server scenario (like ASP.NET).  This is a big change from previous releases of SQL CE – which were designed for client-only scenarios and which explicitly blocked running in web-server environments.  Starting with SQL CE 4 you can use it in a web-server as well. 

There are no license restrictions with SQL CE.

Easy Migration to SQL Server 

SQL CE is an embedded database – which makes it ideal for development and light-usage scenarios.  For high-volume sites and applications you’ll probably want to migrate it to use SQL Server Express (which is free), SQL Server or SQL Azure.  These servers enable much better scalability, more development features (including features like Stored Procedures – which aren’t supported with SQL CE), as well as more advanced data management capabilities.

We’ll ship migration tools that enable you to optionally take SQL CE databases and easily upgrade them to use SQL Server Express, SQL Server, or SQL Azure.  You will not need to change your code when upgrading a SQL CE database to SQL Server or SQL Azure.  Our goal is to enable you to be able to simply change the database connection string in your web.config file and have your application just work.

Summary

SQL CE 4 provides an easy, lightweight database option that you’ll now be able to use with ASP.NET applications.  It will enable you to get started on projects quickly – without having to install a full database on your local development box.  Because it is a compatible subset of the full SQL Server, you write code against it using the same data APIs (ADO.NET, Entity Framework, NHibernate, etc).

You will be able to easily deploy SQL CE based databases to a remote hosting account and use it to run light-usage sites and applications. As your site traffic grows you can then optionally upgrade the database to use SQL Server Express (which is free), SQL Server or SQL Azure – without having to change your code. 

We’ll be shipping the first public beta of SQL CE 4 (along with IIS Express and several more cool things I’ll be blogging about shortly) next week.

Hope this helps,

Scott

P.S. In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu

Help Make WCF Interop Even Better

Speaking of Interop, the .NET Windows Communication Foundation (WCF) team is planning its next set of features and wants to hear from developer’s experiences about how we can make WCF interop better and easier. For that purpose, we have provided a quick, to-the-point survey for you to provide developer-to-developer feedback.

We are early in the product cycle, but need your feedback by July 15th to truly make the impact we all want.

The survey is here: http://mymfe.microsoft.com/WCF/Feedback.aspx?formID=283.

If you have any questions on the survey, please contact Abu Obeida Bakhach, Interoperability Program Manager at [email protected]

Thanks!

New Web Services Interop site on MSDN

Interoperability has been a primary goal of the web services standards from the beginning.  After all, why would you go to the trouble to form a cross-industry initiative to essentially re-invent advanced distributed programming protocols like CORBA and DCOM, unless you could create standards that were broadly supported and truly interoperable?  Interoperability is also fundamental to the whole promise of service-orientation.  From it’s inception, WCF was created to enable this interoperable, service-oriented vision. 

Achieving something of this scale on an industry-wide scale is not an easy task.  It’s been a long road, but Microsoft and the other platform vendors have stuck with the vision of SOAP and WS-* and the end result is solid and getting better with each release of the various platforms that support it.

 

We’ve just published a new page on MSDN to be the one place you can go to learn about web services interop.  We have information there about current interop test results between WCF in .NET 4 and the latest releases of the major Java web services stacks.  We also have white papers that show specific scenarios that are supported and How-To guidance for developers.  And we have information about the various interop activities and communities Microsoft is involved in.  Check it out.

New Sample: Consuming ACS and Service Bus from Flash

As part of the Windows Azure AppFabric July Release, we have added support for cross-domain policy files to enable cross-domains calls to Service Bus and Access Control Service from Silverlight and Flash clients. This new sample demonstrates how to consume the AppFabric Access Control Service (ACS) and the Service Bus’s Message Buffer API from a Flash application.

You will find the sample as an attachment to this post.  Enjoy!

 

If you have any issues/questions/feedback with this sample, please address them in the Windows Azure AppFabric forums

BizTalk 2009 Project System – Repair or no repair?

Hi all

I just had the funniest (NOT) experience (AGAIN) with the new BizTalk 2009 project
system.

Somehow I had gotten into a situation, where I could add all the usual artifacts to
a BizTalk project except schemas. I could add orchestrations, send pipelines, receive
pipelines, maps, flat file schemas, property schemas, and flat file wizard schemas.
So the only thing I couldn’t add was “normal” schemas.

I thought: Who cares? I can just add either a property schema or a flat file schema
instead and then change the necessary properties on it to make it a normal schema,
and that worked for me for some time.

Then, I was contacted by Microsoft to test out a new QFE package that they have created
to fix an issue I have reported. The QFE package wouldn’t install, so i thought it
might have something to do with my project system being broken, so I chose to repair
my BizTalk installation.

The result was, that now I can add “normal” schemas, but I can’t add orchestrations
and property schemas. Also, naturally, the QFE package still doesn’t install 🙁 So
I ended up unconfiguring, uninstalling, reinstalling and reconfiguring. Everything
seems normal now. But for how long?

I really hope they have improved the project system for BizTalk 2010.



eliasen

System.Web.Routing RouteTable not working with IIS?

Most of the time I write simple apps that run in the local ASP.NET development server.  I noticed when I started working with IIS more because of Windows Server AppFabric that my routes were not working when the web application is deployed in IIS.

For Visual Studio 2010 / .NET 4 and IIS 7.5 here is what I’ve learned.

Step 1 – Make sure that you have installed the HTTP Redirection feature

This one was the killer for me.  I didn’t realize that this is not setup by the Web Platform Installer.

Step 2 – Modify your web.config

You are going to need the following

  <system.webServer>

<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRoutingModule"/>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
<handlers>
<add
name="UrlRoutingHandler"
preCondition="integratedMode"
verb="*" path="UrlRouting.axd"
type="System.Web.HttpForbiddenHandler, System.Web,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a"/>
</handlers>
</system.webServer>

 

Step 3 – Create your routes

RouteTable.Routes.Add(

new ServiceRoute("AdventureWorks",
new DataServiceHostFactory(),
typeof(AdventureWorks)))

WCF Messages Not Getting Closed

I spent some time yesterday evening tracking down an issue with a custom WCF transport channel. This particular channel would support the IInputChannel channel shape, but with a twist: it would return a custom implementation of System.ServiceModel.Channels.Message instead of one of the built-in WCF implementations.
There’s nothing wrong with that and it was working just fine […]

AppFabric-enabled WCF Data Service Walkthrough (C#)

In this walkthrough I’ll show you how to use the AppFabric-enabled WCF Data Service (C#) template for Visual Studio 2010 to enhance your WCF Data Services by providing

  • Monitoring events and errors to the AppFabric Data Store
  • Eliminating the need to use the .svc extension in your URI

Requirements

Step 1 – Create a Web Application

  1. Start Visual Studio 2010
  2. Select File / New Project
  3. Choose a Web Application Template – for this example I used Empty Web Application

Step 2 – Add an ADO.NET Entity Data Model

  1. For my database I’m using the AdventureWorksLT sample database for SQL Server 2008R2
  2. Right click on your project and select Add / New Item…
  3. Select the ADO.NET Entity Data Model template
  4. Name the model AdventureWorks.edmx
  5. Select Generate From Database
  6. Connect to AdventureWorksLT and use the default settings
  7. Select all the tables by checking the Tables checkbox

Step 3 – Add an AppFabric-enabled WCF Data Service

  1. Right click on your project and select Add / New Item…
  2. Select Online Templates
  3. In the search box type AppFabric
  4. Select the AppFabric-enabled WCF Data Service (C#) template
  5. Name it AdventureWorks.svc 
  6. Click Install to install the template on your machine

Step 4 – Modify the template code

We have added TODO tasks in the template to guide you through tasks you need to do to make your service ready

  1. Replace [[class name]] with AdventureWorksLTEntities
  2. Modify the SetEntitySetAccessRule code as shown for all entities (“*”)
  3. If you want to use a different route you can set that as well
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
{            
    // Enable read only access to all entities
    config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
    config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;

    RouteTable.Routes.Add(
        new ServiceRoute("AdventureWorks", new DataServiceHostFactory(), typeof(AdventureWorks)));
}

Step 5 – Modify the web.config

  1. In AdventureWorks.svc.cs expand #region Sample Config with End-To-End Monitoring enabled”
  2. Select the commented XML and uncomment it (Ctrl+K, Ctrl+U)
  3. Copy it to the clipboard
  4. Comment it again (Ctrl+K, Ctrl+C)
  5. Open web.config
  6. Paste the XML inside the <configuration> tag
  </connectionStrings>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <diagnostics etwProviderId="830b12d1-bb5b-4887-aa3f-ab508fd4c8ba">
      <endToEndTracing propagateActivity="true" messageFlowTracing="true" />
    </diagnostics>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <etwTracking profileName="EndToEndMonitoring Tracking Profile" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="UrlRoutingModule"/>
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </modules>
    <handlers>
      <add
      name="UrlRoutingHandler"
      preCondition="integratedMode"
      verb="*" path="UrlRouting.axd"
      type="System.Web.HttpForbiddenHandler, System.Web, 
                      Version=2.0.0.0, Culture=neutral, 
                      PublicKeyToken=b03f5f7f11d50a3a"/>
    </handlers>
  </system.webServer>
</configuration>

Step 6 – Run the Service in IIS

To see the events in Windows Server AppFabric you need to deploy the Web project to IIS or modify your project to host the solution in the local IIS Server.  For this example I’m going to modify the project to host with the local IIS server.  Note: This requires you to run Visual Studio as Administrator

  1. If you are not running Visual Studio as Administrator, exit and restart Visual Studio as Administrator and reload your project.  For more information see Using Visual Studio with IIS 7
  2. Right click on the WebApplication and select properties
  3. Go to the Web tab
  4. Check Use Local IIS Web Server and click Create Virtual Directory
  5. Press Ctrl+Shift+S to save your project settings (Debugging will not save them)
  6. Open AdventureWorks.svc.cs
  7. Press F5 to Debug
  8. The Service will open in the debugger and show the service document 
  9. Remove the .svc extension from the URI and try it again.  It will work without the .svc extension in the URI. 

    If this isn’t working for you see System.Web.Routing RouteTable not working with IIS?
    If you want to disable the URI with the .svc extension (and eliminate the .svc file) see this post

  10. If you see an error in the event log (Login failed for user ‘IIS APPPOOL\DefaultAppPool’. Reason: Failed to open the explicitly specified database. [CLIENT: <local machine>]) You need to grant permission to IIS Users to access the database
USE [AdventureWorksLT]
GO
CREATE USER [IIS USERS] FOR LOGIN [BUILTIN\IIS_IUSRS]
GO
USE [AdventureWorksLT]
GO
EXEC sp_addrolemember N'db_datareader', N'IIS USERS'
GO

Step 7 – View Events in AppFabric

  1. Start IIS Manager
  2. Open the AppFabric Dashboard
  3. Click one of the links for WCF
  4. Right click on an event and select View All Related Events to see detailed events