Did you know? DZone has great portals for Python, Cloud, NoSQL, and HTML5!

Giorgetti Alessandro has a Degree in Engineering, he is a ‘Software Artisan’ and co-founder of SID s.r.l. a company which mainly builds products and custom solutions for the Medical HealthCare System. He's one of the co-founders of the .Net user group DotNetMarche and he’s an active speaker in many of the workshops the group organizes. He's a Microsoft MCP specialized in desktop and web application development using .Net technologies. He likes sharing his experiences and experiments about WPF, Silverlight, ASP.Net programming and more through his blog. He got involved in some Open Source projects, but actually his main focus is on Dexter Blog Engine. Alessandro is a DZone MVB and is not an employee of DZone and has posted 15 posts at DZone. You can read more from them at their website. View Full User Profile

Cut the Cable: Configuring WebMatrix/IIS Express to work with WP7 on Windows 7

02.08.2012
Email
Views: 348
  • submit to reddit

A long time has passed since my last ‘notable’ blog post, I was just too busy and lazy in the past months, lots of things happened and I couldn’t follow everything.  But that's not what I want to talk about, let’s talk about some more WP7 development.

Actually I am ‘playing’ with WP7, jQuery Mobile, WCF services and some various mobile stuff these days, honestly I was tired of having my WP7 device connected to the USB cable in order to be able to surf websites and use services that are hosted on my development machine. So I started scouting around looking for a solution.

My goal is to be able to host websites and WCF services using WebMatrix ad IIS Express at first and a custom made WCF self hosting solution at a later time for my developing everyday life (and for demo purposes).

So here’s my current setup:

  • IIS Express/WebMatrix
  • Zune
  • WP7 + USB cable connected
  • a fantastic website hosted on IIS Express


Everything is working correctly here, I can browse the website from WP7 and test it, but I have to keep the cable connected, which is a no go if I want to make a demo of something to someone with a ‘floating’ device. I do not want to create new DNS entries, nor touch the network infrastructure nor do any other complicated IT or network related stuff, that’s not for me.

I want to be able to switch to this setup (both for testing and demo environment):

  • IIS Express/WebMatrix
  • WP7
  • still my fantastic website hosted on IIS Express


You see: no Zune, no cable, just me and my device (and Visual Studio of course). To obtain this we need to make IIS Express able to accept connections from the outside, you can do that following this guide:

http://blogs.iis.net/vaidyg/archive/2010/07/29/serving-external-traffic-with-webmatrix-beta.aspx

Here’s what I had to do in order to make things work:

  • Get your computer IP, mine was: 192.168.1.10.
  • Pickup a port you will use to host your service (using port 80 is bad idea on a development machine), I choose: 24778.
  • Configure HTTP.SYS (the component that is used to handle http requests) to accept external connection when running as standard user (you can bypass this if you launch WebMatrix and IIS Express with admin privileges, but that’s not good for security reasons), open a shell prompt with admin rights and type:

    netsh http add urlacl url=http://192.168.1.10:24778/ user=everyone
    
  • Configure the binding in WebMatrix: doing it by manually editing the applicationhost.config file is the best way. The file is located is your user profile at the following folder: “%USERPROFILE%\documents\IISExpress\config”. Another way to find it is: right click on the IIS Express icon in the system Tray, choose “show all applications”, highlight your website and then look at the configuration setting (it’s the last voice on the window), you can even click on it to open the file in notepad.

    WebMatrixWp7_1

    The image is in Italian, I know Open-mouthed smile; now that you have your file open you need to locate the your website configuration and change the binding settings to allow connection the pre-defined IP address and port. Here’s how I modified my configuration:

    <site name="MyWonderfulSite" id="2">
     <application path="/">
         <virtualDirectory path="/" physicalPath="D:\XXXXXXXXXX" />
     </application>
     <bindings>
         <binding protocol="http" bindingInformation="*:24778:localhost" />   
         <binding protocol="http" bindingInformation="192.168.1.10:24778:" />   
     </bindings>
    </site>

  • have added a binding that explicitly configure the IP address and port that I want to use without assigning a hostname.
  • The last step is to open up the port in your Firewall, this is up to you depending on the Firewall you are using.

 

If you have followed all the steps you are now able to browse your test website (using the specified address like: http://192.168.1.10:24778/) from your WP7 without having the USB cable connected and Zune open, pretty cool isn’t it ?

These very same steps can be used for your Android and iPhone devices, but I personally do not own any of those devices so I wasn’t able to try it.

Doing this research I’ve learned a couple of things about IIS Express and how the http requests are served by the system.

As last note: to undo the modifications you’ve done to the HTTP.SYS configuration you can use the following command:

netsh http delete urlacl url=http://192.168.1.10:24778/


See you next time.


Source: http://www.primordialcode.com/blog/post/configure-webmatrix-iis-express-wp7-windows7
Published at DZone with permission of Alessandro Giorgetti, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)