Having had some time to digest all the news from MIX08 I am working on converting a Silverlight 1.1 project to Silverlight 2.0. One of the major changes is to move from ASMX services to WCF services. Now, that cross-domain access is possible and with WCF inherently being more complex there are a lot of failure points.
So, having spend probably a total of 8 hours on updating the structure of the new project and deploying it to a production environment I thought I'd share this with you so you don't have to spend that much time. Since most of the time spent had to do with deployment and WCF configurations I will focus on that.
The 3 main challenges I needed to figure out were...
- Windows authentication versus Anonymous authentication. This is solely WCF and doesn't have to do with Silverlight directly.
- Cross-domain access. This is important when troubleshooting your service, which has been deployed to production, and referencing it within your local Visual Studio Silverlight project.
- Asp.net Compatibility. Again, WCF only configuration.
1. Windows vs. Anonymous authentication.
By default, WCF requires you to have your IIS virtual directly configured to be accessible anonymously. However, if you do some kind of domain related stuff you need your IIS virtual directly to be configured to be Windows Authentication. Here is the code to update your web.config file of the WCF web application.
<transport clientCredentialType="Windows" />
<service behaviorConfiguration="DesignDBServiceBehavior" name="DesignDBService">
2. Cross-domain access.
I mainly just needed to get this working because I tried to debug my local SL project having referenced and external cross-domain WCF service. In order to get this working you need to put a "clienataccesspolicy.xml" in the root of your IIS server. This is usually at C:\inetpub\wwwroot. If the file is there and granted the file allows your local domain of your SL project access, Silverlight will automatically acknowledge the file and give access. So, there is nothing you need to do within Silverlight. HOWEVER, MAKE SURE TO RESTART IIS. THE FILE IS NOT RECOGNIZED RIGHT AWAY.
<?xml version="1.0" encoding="utf-8"?>
<resource path="/" include-subpaths="true"/>
3. Asp.net Compatibility
This involves two steps
1. Change to the web.config file of the WCF web application.
add this line into the root of <system.serviceModel>.
2. Adding of a class property of the service class, not the service interface.
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class DesignDBService : IDesignDBService