Android Addicted Apps Creator

December 23, 2009

Deploying Silverlight WCF service from developement station to IIS

Filed under: Silverlight — alinberce @ 10:52
Tags: , ,

 

The beginnings…. 

I have created a Silverlight application that uses some data taken from an almighty SQL Server. To bring data I used Silverlight enabled WCF Services. The Visual Studio solution contains the Silverlight application project and the added Web site to display the Silverlight control.  The web application contains the WCF Service and the service is referenced in the Silverlight application project.

The Solution looks like this:

SilverlightWeb – the web application, contains a folder WCFServices in which I have Service.svc

SilverlightApp – Silverlight control that references Service.svc

When I ran the solution from within Visual Studio’s internal IIS server everything works fine, I can see the SQL data in the Silverlight control.

If I try to access the .svc file from the browser accessing the http://localhost:1487/WCFServices/Service.svc I can see a page with "You have created a service.", so it’s fine.

When I was ready with milestone one of the project I decided to give it a test-drive on the IIS production server . In order to deploy the solution to the IIS Production server I took the SilverlightWeb folder and copied it on the wwwroot folder. I created a Virtual Directory for SilverlightWeb folder. The .svc extension appears to be registered on the IIS. Before deploying I also modified the ServiceReferences.ClientConfig file, setting the endpoint address from

endpoint address="http://localhost:1487/WCFServices/Service.svc"

to

endpoint address="http://IIS Server’s IP address/WCFServices/Service.svc"

When I try to access from browser (http://IIS Server’s IP address/SilverlightWeb/TestPage.html), I can see the silverlight control, but when I press the button that calls the WCF Service nothing happens.

I tried to access the WCF service directly to see: http://IIS Server’s IP address/WCFServices/Service.svc  and gives me a File not found error

If I access using http://IIS Server’s IP address/SilverlightWeb/WCFServices/Service.svc I get a window where it says

<%@ ServiceHost Language="C#" Debug="true" Service="SilverligtWeb.WCFServices.Service" CodeBehind="Service.svc.cs" %>
 

The cursing…

In order to make the solution work on IIS I did everything I could find over the Google. I was really pissed off because WCF seemed such a fine concept but I couldn’t use it. It took me almost one week to find the answers… the good thing is that meanwhile I had other things to think about, rather than cursing. I have a straight rule: if it isn’t broken, don’t break it. Of course, the IIS server was fully used by a bunch of final users and I couldn’t risk making all kind of trial and error on it in order to make WCF service work. So, I made a full Backup and restore it on on PC. After all the hassle of restoring the image, driver install, network configuration… when everything was ready (took me 2 days) in 5 minutes I got the solution working. As my good friend, Emanuel said: It’s probably a 2 minute thing. Well, it was a simple thing. Emanuel also recommended me a great piece of software: Fiddler2. It is very useful to see what connections are being made from the browser, as it acts like a proxy between the browser and the network.

The solution…

Three baby steps were needed in order to solve the issue:

1.  Make sure that .Net 3 or 3.5 is installed on the IIS

2. Configure the IIS metabase to pass .svc files to ASP.NET and then on the WCF. The .svc was handled as static content.

Thank you Richard Blewett for these two steps.

3. A final step would be modifying the endpoint address (again) to be correct. When in Visual Studio internal IIS, there was no virtual directory created in order to run the project locally. When I deploy it on IIS I made a virtual directory so the endpoint address should be updated in order to have the correct path to .svc file.

endpoint address="http://IIS Server’s IP address/WCFServices/Service.svc"

to

endpoint address="http://IIS Server’s IP address/VirtualDirectoryMadeForSolution/WCFServices/Service.svc"

If still doesn’t work, please check to see if .svc extension is registered. If no, manually register it.

Well that’s all. I had to learn a little Silverlight. It is indeed a great technology that allowed me to make thing I could even think possible in a browser.