Silverlight enabled WCF service deployment on IIS

 

INTRODUCTION

I just completed one of my Silverlight 4 project. In this project I used Silverlight Enabled WCF service for handling my database operations. As the project requirements was just to read the data from the database via stored procs and display it on the datagrid. I intentionally didn’t use WCF RIA services as I thought this would be an overhead for this type of requirement. Both WCF Ria service (Domain Service) and Silverlight enabled WCF service works on the core principles of WCF technology. The difference is that lot of code is generated by Ria Services framework and there is no physical .svc file in your project whereas in the Silverlight enabled WCF service you have .svc file with you and things are more under your control. Both supports Asynchronous service operations. Besides this when you add a service reference to your Silverlight project from the solution a new file called “ServiceReferences.ClientConfig” is also created which plays key role, read further.

THE DEPLOYMENT GOTCHAS

The solution worked like a gem in my Visual Studio 2010 development environment , which uses Cassini web server. But when it came to deployment on IIS , I ran into issues. As usual the server returned the infamous error “NOT FOUND” to Silverlight client. I was already aware of RIA deployment problems and I tried all those steps but all in vain. Then Fiddler came to my rescue. This is awesome http debugging tool and I really love it. After analysing the fiddler output I was shocked that my .svc url was still pointing to the localhost. Holy crap what is that I was totally lost and didn’t know what was happening. Though my address attribute in the endpoint element of web.config file was pointing to the correct path of my IIS virtual directory, then where did I go wrong.

SOLUTION

I didn’t gave up so easily , I started digging out forums , googling , binging whatever you can add over here. But could not find anything concrete which could solve this issue. Then Visual Studio intellisense helped me. I came to know that the proxy service class that was generated by Visual Studio has more than one constructor, five to be precise. The third constructor which accepts the two parameters endpointConfigurationName and remoteAddress. See the below screen shot.

VS2010 Intellisence

From the code you can see it was matter of two lines which made me rest in peace. The code is pretty self explanatory. I declare the objUri variable and initialize with .svc path. As mentioned earlier here we have physical .svc file present and this should be also deployed on IIS. The Application.Current.Host.Source returns you the .xap file path and as my .svc file was located in the root of virtual directory I used ../ and the .xap file was located in the ClientBin folder. The second line of the code does the magic. Here I have used the endpointConfigurationName from the ServiceReferences.ClientConfig file. Remember what I told in the beginning. This is a string value which is auto generated by Visual Studio and finally the second parameter is fully qualified path of service file. After making these changes I rebuild the solution , did a deployment using Publishing Wizard and viola my application started working.

CONCLUSION

I am still in the process of finding that even though when I specified the endpoint address in the web.config file why the service was referring to my localhost. I thought that should have resolved the issue but it didn’t work. Now my address attribute in web.config is empty string and I am not require to deploy the ServiceReferences.ClientConfig file on IIS. It just simply works with these two magical lines of code. Hope this solution will help the community in their deployment issues and they don’t undergo the struggle period that I went. After all learning is all about sharing. Let me know your thoughts for the same.

Cheers

Advertisements

9 thoughts on “Silverlight enabled WCF service deployment on IIS

  1. Hi!

    Do you have .NET Framework 4.0 installed on your Windows Server 2003. I am using vs2010 to develop SL4 app + SL enabled WCF service. My testing server is Windows Server 2008 R2 and it has .NET Framework 4 on it. The SL 4 app + SL enabled WCF service work perfectly. However, the production server is Windows Server 2003 with IIS 6 and only .NET 2.0 and .NET 3.5 SP1 on it. I wonder if lacking .NET 4.0 on the production server will make any issue to run SL enabled WCF service.

    Please advise.

    Thanks.

    Sheng-Te

    • Hi,

      Yes indeed I have .net Framework 4 installed on my production server and IIS App pool also points to this version of Framework.

      Regards

      • goldytech,

        Thanks for your response. Do you think if it will case a problem if my production server does not have .NET 4.0 on it?

        Sheng-Te

      • Hi Sheng

        Please understand that silverlight is a client side technology which gets hosted on the asp.net web application. Your server should have all the prerequists that are required to run the asp.net application. On the client side you just require silverlight browser plugin.

        I hope this helps.

        Thanks
        Goldy

  2. Ok! So I think I still need to have .NET 4.0 to run the SL enabled service built in vs2010. Otherwise, I can only use vs2008 to build a SL3 app + SL enabled wcf service so I can be run them in IIS 6 with .NET 3.5 SP1 but not 4.0.

    Thanks,

    Sheng-Te

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s