Silverlight gains a key feature

Posted by jeff on Nov 12th, 2007

Great news for Silverlight adopters:  It looks like Silverlight 1.1 will have a SaveFileDialog.

"The good news is that we are planning on adding a SaveFileDialog() before the final release of Silverlight 1.1.", from Scott Guthrie's blog.

We were crossing our fingers for this feature.  See our previous post (Silverlight's niche, and its missing piece) on the subject.

With this small addition, you can write a web application that opens,  edits, and saves a file, without necessitating server intervention.  This opens up the possibility of replacing a variety of utilities with web-based counterparts which can enjoy active development.

Here are a few such applications which could make the jump to the browser (actual names concealed to protect these innocent applications):

Packing it up and moving to the browser?

Can you think of others?  Could you trust a web application to help with these tasks?

How to create REST/POX web services with WCF

Posted by adamjh on Nov 6th, 2007

After a horribly unfulfilling day of hacking at .Net, Perl, and Ruby SOAP implementations... trying to get them to talk nicely to each other... I went to sleep last night with the realization that attempting to achieve interoperability through SOAP would be a never-ending war.

So, I woke up this morning with the desire to make some of our .Net web services RESTful.  One of the great things about Windows Communication Foundation (WCF), the subset of the .Net Framework that provides web service capabilities, is the ability to switch between SOAP/REST and POX/JSON configurations without changing most of your underlying code.

Unfortunately, with .Net 3.5 and Visual Studio 2008 still in beta (for at least a few more weeks anyway), I couldn't find any good documentation/tutorials/howtos on how to do this.  So, after a lot of trial and error, here are the steps to successfully create a RESTful web service with Plain Old XML endpoints, starting with the sample WCF Service Application template that ships with Visual Studio:

1. Create a new WCF Service Application

In Visual Studio, create a new Visual C# project using the "WCF Service Application" template.

2. Add a RESTful service endpoint

In your application's configuration file (Web.config or App.config), add the following endpointBehaviors section right above the existing serviceBehaviors section.  It should now look something like this:

    <behaviors>
      <
endpointBehaviors>
        <
behavior name="webBehavior">
          <
webHttp />
        </
behavior>
      </
endpointBehaviors>
      <
serviceBehaviors>

Now add the following "rest" endpoint to your existing service section so that it looks like:

      <service name="RESTService.Service1" behaviorConfiguration="RESTService.Service1Behavior">
        <!--
 Service Endpoints -->
        <
endpoint address="" binding="wsHttpBinding" contract="RESTService.IService1"/>
        <
endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <
endpoint address="rest" behaviorConfiguration="webBehavior" binding="webHttpBinding"
         bindingConfiguration="" contract="RESTService.IService1" />
      </
service>

3. Reference System.ServiceModel.Web 

Add a reference to the .Net System.ServiceModel.Web assembly.  You can do this by going to Project->Add Reference, and selecting "System.ServiceModel.Web" from the .NET tab.

At the top of your service interface file (i.e. IService1.cs), add:

using System.ServiceModel.Web;

4. Add a WebGet attribute

The default sample GetData() method in your service interface file should look like:

        [OperationContract]
        string GetData(int intParam);

We'll make this RESTful and accessible through HTTP GET by adding a WebGet attribute:

        [OperationContractWebGet]
        string GetData(int intParam);

Testing it out

At this point, you should be able to build and run your program, and access your new RESTful web service at the following URL:

http://localhost:[port]/Service1.svc/rest/GetData?intParam=1337 

You should get the following output:

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">You entered: 1337</string>

Note: [port] will be chosen at random when you build and run your program from within Visual Studio.  When you run for the first time, you will see a notification with the port in the system tray.  You can also hover over the ASP.NET Development Server icon in the system tray at any time to find the port number.

Using HTTP POST and URI Templates

If you want to submit information to your service using HTTP POST or another HTTP method, simply replace the WebGet attribute with the WebInvoke attribute, whichdefaults to POST and has an optional Method parameter (for PUT, DELETE, and other less common methods).

If you want to use a different URI scheme, WCF makes it really easy to do so.  For example, try:

        [OperationContractWebGet(UriTemplate = "data/{intParam}")]
        string GetData(string intParam);

And now try accessing your service at:

http://localhost:[port]/Service1.svc/rest/data/5 

Notes: We had to change the intParam from type int to type string, because URI Templates expect string parameters.  Inside of the GetData() method, we could convert the parameter back to an int with a simple call to int.Parse(intParam).  It's also possible to clean up the "Service1.svc" and "rest" URI sections by changing the service host and endpoint addresses.

Hope this helps anyone out there trying to get started creating a simple REST/POX web service with WCF.  This should be significantly better documented in the near future as Visual Studio 2008 RTMs.  At that point, some of the snippets above may need to change slightly depending on any changes that have been made to the framework or the sample applications since Beta 2 -- if you notice any issues or find this useful, please post a comment!

Also, for a lot more background on web services in .Net, check out Steve Maine's blog.  I saw him speak earlier this year at MIX, and he and his team are doing some really great work at Microsoft in this area.

City Slicker

Posted by vikas on Nov 5th, 2007

Twelve days ago I was living in New York City. I was working at Xanga.com a blogging,social networking, and interactive TV site. I had an awesome group of friends which included people at work (employee count 18, average age 26). I was working on cool and challenging web applications that are used by millions of people. I loved the people I worked with. We had beer in the fridge and a ping pong table. The experience was a lot like being in college but getting paid for it. I got to explore a city so alive with millions of fascinating and different people that it is not possible to be bored unless you are trying.

Then on October 25th, I quit my job and moved from NYC, population of around 19,000,000, to an island of roughly the same size, Beaver Island with a population of 600 to join Jeff and Adam in the founding of a new company.

Why would I leave a job, city, and people I love to come to Beaver Island? Now I will admit that I'm the kind of person that likes rocking the boat just to see what will happen, but that's not really why. I want to be part of bringing an intelligent internet into the real world experience of the average person, and I think that we have an opportunity to do that. I also love working on really hard and interesting problems, especially when nobody else has really solved them. Computers can do much more interesting and exciting things than they are doing now, and I think that our company can help make this happen.

I met Jeff back in sophomore year of college at a Tau Beta Pi/ Eta Kappa Nu (both are engineering honor societies) bowling party. I remember trading him some candy for chicken wings. In fact here's an article that I wrote about him back in the day (go to page 2).

As for Adam, I actually met him when me and one of my best friends Greg were biking from San Francisco to Los Angeles. Me, Greg, and my friend Jodi (who lives near LA) got to see the LA office of Adam and Jeff. We also all went out later to a karaoke place where Adam's sweet voice removed any doubts I had in my mind about joining him and Jeff.

We've hit the ground running on Beaver Island, and I've started adding to our growing pile of code!

Vikas

My one-way ticket to Beaver Island.

Fun Beaver Island Facts:

  • If you're running around town, everyone waves at you from their cars.
  • Turkeys are plentiful on the island and apparently pretty tame. Jeff's dad knows how to turn a wild turkey running around in the yard into a turkey ready to eat using only a rifle and an oven. It was delicious!
  • The only other Indian people on this island are American Indians.
  • The runway at the airport is made of grass.