Yavor Georgiev

Yavor is a PM at Snowflake working on developer experience. Previously at Docker, Auth0, Hulu, and Microsoft Azure.

Silverlight Firestarter demo

09 December 2010

In my previous post I linked to the video and slides from my talk. This point contains the code sample, which is available here.

Setting up your machine

Here is what you need on the machine before you get started:

  • Windows 7
  • Visual Studio 2010
  • Silverlight 4 tools for Visual Studio 2010
  • SQL Server 2008 Express (which I’m pretty sure comes with Visual Studio 2010 by default)
  • IIS7

Before you proceed, make sure the user account under which SQL Server Express is running is NETWORK SERVICE. If you don’t remember how this was installed, open up Task Manager (make sure you select “Show processes from all users”) and look for the sqlsevr.exe process. If you find that you need to change the user, this topic on MSDN should come in handy.

The other tricky part is installing/configuring IIS. Go to the search box in the Start menu and type “Turn Windows features on or off”, then select top result. In the box shown, make sure the following are checked.

Deploying the basic app

  1. Download the zip file and unzip the content in a folder such as C:\Firestarter. It is actually very important to download this in a location other than your C:\Users\YourUser folder, due to an apparent bug with SQL Server Express.
  2. Open Visual Studio as Administrator and open the solution file. You will be prompted to create a new website in IIS, and you should agree. If this succeeds you should see the solution open with both projects loaded correctly. But we’re not quite done yet.
  3. We need to make sure the account under which IIS is running has access to SQL Express. Go into the IIS Manager (type inetmgr into the Start menu search box) and click on Application Pools. Find the ASP.NET v4.0 application pool and then select Advanced Settings on the right side. Find the Identity row and change that to NetworkService.
  4. We also need to make sure that the NETWORK SERVICE user has access to the location where we put our files. Let’s assume you used C:\Firestarter as I recommended above. Go to the the folder properties, then go to the Security tab. NETWORK SERVICE is part of the Users group on any machine, so we can just make sure that the Users group has read and write  permission. If you don’t see  the Users group go ahead and add the NETWORK SERVICE account explicitly here and give it read and write permission. Make sure the permissions are inherited all the way down, especially to the App_Data folder and the .mdf files inside that folder. You should double-check that every .mdf file allows the Users group or the NETWORK SERVICE account read and write permission. Otherwise you will get a stream of inexplicable errors as you attempt to follow the rest of this post.

You should now be able to hit F5 in Visual Studio, the application should pop up and you should be able to see the book categories and click on individual books.

At this point you can also try and use the demo to enable the debugging features I cover in the video.

Setting up Windows Authentication

Needless to say, before we can demonstrate this scenario, we need to make sure the machine we are using is joined to a domain.

We need to do the IIS configuration step that I refer to in the video, but I don’t show. We can open IIS Manager and find our web application, then double-click the Authentication icon and make sure Windows Authentication is enabled.

We can then follow the rest of the steps as shown in the video. One exception is that instead of my personal domain credential, you will need to specify your own domain credential in the BookService.svc.cs code behind file. In the download I’ve changed it to domain\user.

Setting up Forms Authentication

Before we can get this to work, we need to first configure our website for access over HTTPS. Like I mention in the video, this authentication scheme requires HTTPS.

  1. Back in IIS Manager we need to enable HTTPS on the Default Web Site bindings list. You can follow this tutorial by ScottGu.
  2. Once the HTTPS binding is created for the parent website, we need to enable the HTTPS protocol for our BookService.Web site. We can do that by going to Advanced Settings and adding https in the list of Enabled Protocols. The values are comma-separated in case you were wondering.
  3. If you end up using a self-signed certificate, realize the IE will display an error page warning you that the cert is not signed. That means that any calls that Silverlight tries to make to that page will be blocked automatically. The easiest way to fix this is to go over to Internet Options > Advanced and in the Security section deselect “Warn about certificate address mismatch”. Don’t forget to restart IE afterwards, and most importantly, don’t forget to reenable this option when you are done playing with the demo.
  4. The last thing we need to realize is that we will be accessing the SL application over HTTP, but internally it will be making calls to HTTPS services. This is cross-scheme access and is normally disabled, even for same-domain calls. To address this we need a special clientaccesspolicy.xml file, which we place at the root of our IIS install, in my case that is C:\inetpub\wwwroot. The file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
   <cross-domain-access>
      <policy>
         <allow-from http-request-headers="SOAPAction">
            <domain uri="http://localhost"/>
         </allow-from>
         <grant-to>
            <resource path="/BookShelf.Web" include-subpaths="true"/>
         </grant-to>
      </policy>
   </cross-domain-access>
</access-policy>

Once all of this is done, we can go ahead and follow the steps in the video. Please look carefully at both Web.config and ServiceReferences.ClientConfig to make sure you comment out all sections that refer to ASP.NET authentication.

That is it, please let me know if you hit any issues in the comments.

Cheers,
-Yavor

Read More

Silverlight Firestarter 2010 talk and demo

08 December 2010

Thanks to the folks that attended either in pesrson or through the live webcast. I enjoyed giving this talk and I hope you found it useful.

The slides for the talk are available here.

The demo from the talk is available here.

Read More

JsonValue guts and glory

29 October 2010

As part of the new set of WCF features at http://wcf.codeplex.com, we’re porting a feature that has existed in Silverlight to the framework. JsonValue is the base abstract class for a set of types that you can use to work with JSON data in a weakly-typed way: JsonPrimitive, JsonArray, and JsonObject. The idea here is similar to how you use XElement to work with XML data: you don’t need to pre-generate a strong type to deserialize into.

Basics

We start with a JSON string, and we parse it easily in one line.

~~~ javascript string customers = @” [ { “ID” : “538a868a-c575-4fc9-9a3e-e1e1e68c70c5”, “Name” : “Yavor”, “DOB” : “1984-01-17”, “OrderAmount” : 1e+4, “Friends” : [ “007cf155-7fb4-4070-9d78-ade638df44c7”, “91c50a40-7ade-4c37-a88f-3b7e066644dc” ] }, { “ID” : “007cf155-7fb4-4070-9d78-ade638df44c7”, “Name” : “Joe”, “DOB” : “1983-02-18”, “OrderAmount” : 50000, “Friends” : [ “91c50a40-7ade-4c37-a88f-3b7e066644dc” ] }, { “ID” : “91c50a40-7ade-4c37-a88f-3b7e066644dc”, “Name” : “Miguel”, “DOB” : “1982-03-19”, “OrderAmount” : 25.3e3, “Friends” : [ “007cf155-7fb4-4070-9d78-ade638df44c7” ] } ]”;

Read More

WCF and JavaScript clients at PDC 2010

26 October 2010

As you may have heard from @gblock WCF is making some significant new investments around HTTP to make sure HTTP-based services are first-class within our stack. As part of this effort, we are renewing our focus on JavaScript clients and jQuery in particular. To learn more, check out Glenn’s PDC10 talk:


Building Web APIs for the Highly Connected Web
Friday 10/26/10, 9:00 AM-10:00 AM (GMT-7)
In person: Kodiak Room / Microsoft Campus Redmond, WA
Live stream: http://player.microsoftpdc.com/Session/17a9e09f-4af1-4ef3-8a5a-ebf1e9bd9c8e 

And to leave you with a little teaser… join us for the talk to find out more!

~~~ csharp WebClient client = new WebClient(); string result = client.DownloadString(“http://search.twitter.com/search.json?q=%23PDC10”);

Read More

Getting the WebOperationContext of a HTTP response in Silverlight

20 October 2010

This came up as a question from a customer today: how do you get details of the HTTP response message that a WCF proxy in Silverlight received? If you thought of  OperationContext and WebOperationContext, you’re on the right track, but you have only half of the story.

In Silverlight, in order to get to these context objects, you have to switch from the event-based async pattern to the more complex Begin/End-based async pattern. Within that pattern, you need to instantiate an OperationContextScope and call the End* method inside that scope, before you can access the context objects themselves. Check out this code snippet:

~~~ csharp public MainPage() { Service1 proxy = new Service1Client() as Service1; proxy.BeginDoWork(new AsyncCallback(Callback), proxy); }

Read More

Speaking at Silverlight Firestarter

13 October 2010

Silverlight Firestarter

Folks, I’ll be speaking on WCF at the Silverlight Firestarter event in December. It’s a one day, global, live streamed and on demand event keynoted by Scott Guthrie. The focus of the event will be to demonstrate that over the last 3 releases Silverlight has grown up to be a very powerful platform for creating engaging experiences on the web/Desktop/phone.

Please click the link to the left to register - it’s free!

Any thoughts on particular web services topics you want me to cover?

Read More