Finally after 3 days and nights i was able to find the solution for hosting RIA services on shared hosting environment and without changing anything on IIS. Yes it is possible…
Why : RIA framework dynamically creates WCF service (Domain services) and add endpoints to the service.It first check if endpoint does’nt exist then create it,and it checks for 3 endpoints (http,soap and binary).After creating end points it adds authentication schema to end points.It picks IIS authentication schema’s and tries to apply on end points and failed to apply.
If we could create desired end points in web.config RIA framework will not create or do anything with endpoints and it works succesfully ..
You just need to follow the simple steps mentioned below :
1. Add following code to you web.config to solve issue “This collection already contains an address with scheme http..”
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"> <baseAddressPrefixFilters> <add prefix="http://www.yoursite.com"/> </baseAddressPrefixFilters> </serviceHostingEnvironment>
Note: Your service can be only accessed by url mentioned in above settings. As configured above you can’t access your service via http://yoursite.com.
You could also use factory code to host WCF (see below) to resolve this error however alone with that you need to create svc files for each domain service.
2.Add AspNetCompatibilityRequirementsMode attribute to your RIA Domain services classes
Eg .Attrubtes added to AuthenticationService class under services folder
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class AuthenticationService : AuthenticationBase<User> { }
RIA framework dynamically apply these attributes after creating end points.Since we are now bypassing endpoint creation , we need to manually apply these attributes.
3. For each RIA domain service add following to you configuration file.
Eg. Is shown for AuthenticationService and UserRegistrationService
Where SparkExams is my custom namespace.
<services> <service name="SparkExams.Web.AuthenticationService" behaviorConfiguration="RIAServiceBehavior"> <endpoint address="" binding="wsHttpBinding" contract="SparkExams.Web.AuthenticationService" /> <endpoint address="/soap" binding="basicHttpBinding" contract="SparkExams.Web.AuthenticationService" /> <endpoint address="/binary" binding="customBinding" bindingConfiguration="BinaryHttpBinding" contract="SparkExams.Web.AuthenticationService" /> </service> <service name="SparkExams.Web.UserRegistrationService" behaviorConfiguration="RIAServiceBehavior"> <endpoint address="" binding="wsHttpBinding" contract="SparkExams.Web.UserRegistrationService" /> <endpoint address="/soap" binding="basicHttpBinding" contract="SparkExams.Web.UserRegistrationService" /> <endpoint address="/binary" binding="customBinding" bindingConfiguration="BinaryHttpBinding" contract="SparkExams.Web.UserRegistrationService" /> </service>
Please note that RIA adds 3 endpoints and if any of these endpoints are missing from web.config it will throw “IIS specified authentication schemes ‘Basic, Anonymous’…” error.
Add following behaviours and bindings to your web.config
<behaviors> <serviceBehaviors> <behavior name="RIAServiceBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <bindings> <customBinding> <binding name="BinaryHttpBinding"> <binaryMessageEncoding /> <httpTransport /> </binding> </customBinding> </bindings>
Test you wcf end points using WCF client test tool (Test client for Windows Communication Foundation services.) WcfTestClient.exe : Go to VS 2008 Console and type WcfTestClient.exe.
Note that there is no need to host you service,or change IIS settings by ISP.
Update : While working on SL project i have noticed that SL is not able to recieve faults/exceptions thrown by RIA domain service.Please follow article to fix the issue “Silverlight Faults in SL 3.0 with RIA Domain Services – Fix 2“ – Must read
Finally code and live demo application link are here..
Demo Application link
/rajnish/RiaTest/
Custom service link
/rajnish/RiaTest/DeployTest-Web-services-CustomService.svc
Link to binay files for above links
/rajnish/uploads/code/RiaTest/Binary.zip
//Source code of application (Web.config has been changed in binary.zip)
/rajnish/uploads/code/RiaTest/Source.zip
If you are having any problem related to hosting Sl,copy binay.zip contents to your virtual directory on web server and modify web.config (bottom)
add prefix=”/rajnish/”
If you have any problem with your code , then please download the binary.zip extract the contents and create virtual directory say RiaTest on your domain and copy the contents of Binary.zip (files like Default.aspx,DeployTestTestPage.aspx etc) to your web server.Change web.config “prefix section as mentioned above.Eg. on my webserver www.rajneeshnoonia.com i have created RiaTest virtual directory and copyied the contents of binary.zip into it.first step is to test your web service with URL like /rajnish/RiaTest/DeployTest-Web-services-CustomService.svc. if web service is ok you can launch your silverlight application.
Note: the site will not work if you try to launch with /rajnish/… rather it will work if you try /rajnish/…

Leave a reply to Paolo Cancel reply