RIA WCF Configuration (Finally Resolved):

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/

69 thoughts on “RIA WCF Configuration (Finally Resolved):

  1. There are lot of changes with WCF RIA Sl4 with Vs 2010.I am waiting for my ISP to provide ASP.net 4.0 version on shared hosting space and in turn they are waiting for microsoft to release ASP.Net 4.0 final version.ISP will not install RC (release candidate) on production web server.

    Like

  2. Well, I finally DELETED my entire domain’s content just to get this f*@#^ working! And, it still doesn’t work.
    I wiped it all out with your test. Here is the test page running on .NET 4 from VS2010:
    http://ericis.com/DeployTestTestPage.aspx
    *I have marked my application full-trust. I have also tried wiping it out with just the “Silverlight BusinessApplication” template in VS2010. No luck there either.
    The thread I’ve been discussing on is at: http://forums.crystaltech.com/index.php/topic,34923.0.html

    Like

  3. Hello Rajneesh,
    still got no luck with VS2010 RIA?
    I got the exception “The contract name ‘xxx.Web.AuthenticationService’ could not be found in the list of contracts implemented by the service ‘AuthenticationService’”
    Thanks

    Like

  4. Please check my article “http://www.rajneeshnoonia.com/blog/2010/08/silverlight-4-0-with-wcf-ria/” which is about how to work with SL 4.0 using 2010 with WCF RIA with Vs 2008.I know this is not the solution but we don’t have any option left till few months.The fix mentioned in this post is for VS 2008 (FW 3.5) and will not work with VS 2010 (FW 4.0).

    Let me know your view…

    Like

  5. Hi Rajneesh,
    I am trying to deploy my first app with Silverlight. In its current state the application works perfectly all right in my development environment. I am using Visual Studio 2008, Silverlight 3 and RIA services beta version 1.0.0.14. with SQL server 2005. The application is based on Silverlight Business application Template.

    • Prior to hosting I have made sure I follow the guidelines mentioned in this blog – http://timheuer.com/blog/archive/2009/12/10/tips-to-deploy-ria-services-troubleshoot.aspx
    • Added to Web.config.
    • Modified the connection string accordingly.
    • Authentication
    • Switched off the basic authentication property in IIS. The only authentication mode enabled is ‘Forms’ and ‘Anonymous’.
    • ASP Setting is done in Web.config.

    Now when I have hosted the application on a server I am getting an error as Load operation failed for query ‘GetUser’. The remote server returned an error: NotFound.
    I am using Fiddler to debug the application on the server.

    On fiddler I can see a HTTP/1.1 500 System.ServiceModel.ServiceActivationException generating at response headers.
    I have also configured IIS on my local machine to make it a dummy server and hosted the application there. I see the same error. But in my local machine fiddler shows a 404 not Found error at response headers. It also tells me the error occurred while trying to access the AuthenticationService.svc/binary file.
    Let me give an overview of my application structure.
    I am using an ASP.net membership provider to handle custom user validating logic against my Database. and I have not done anything on my auto generated AuthenticationService service.
    What I am doing wrong here?
    Please help!!

    Like

  6. Nilarya : The configurations mentioned in this article (http://www.rajneeshnoonia.com/blog/2009/12/ria-wcf-configuration-finally-resolved/) are tested and i am still using this with VS 2008.I would say you can download the attached source code and try to host them.If it works find then go thow the article.You have to add few configurations in your web.config

    You can launch your WCF RIA service end point (URL) and check for asp.net erros.If your wcf service has no errors => your wcf service is hosted properly.The next step is to check if you SL application can use this or not.

    In above mentioned article there is link to another related article which is about handling faults in silverlight.

    Regards
    Rajneesh

    Like

  7. Hi Rajneesh,
    Thank you so much for your suggestion. I created a new virtual directory and hosted your application there. I have followed the steps you have mentioned. But on the browser I see the same error message that I am facing with my aplication. It shows The load operation failed for the query getUser. You can see the error yourself by going to http://www.csoftsite.com/RIA_Test/DeployTestTestPage.aspx
    the only difference being on my app, I cannot see the error details on the server, but I can see te same message that is shown here when I host my app in a locally configured IIS.
    Also, I would like to let you know, I can access my svc service hosted in the server from my browser.

    Could this be an error message generating from the connection string? note that I have not changed the connection string on your web.config. I am really puzzled over this issue. Or there may be some silly spot which I am overlooking?
    Please help.
    Thanks.

    Like

  8. Hi Rajneesh,
    Have you got time to view the above link? this seems a configuration issue in the server to me. But can you suggest what are the changes that we should consider to undertake on the server?

    Like

  9. Nilarya : I was trying to access wcf service url (http://www.csoftsite.com/RIA_Test/DeployTest-Web-services-CustomService.svc) which throws error during service activation (Could not find a base address that matches scheme http for the endpoint with binding WSHttpBinding). Make sure that in baseAddressPrefixFilters you have correct prefix as http://www.csoftsite.com Load operation error occur because your silverlight application tries to access wcf service which is not there..

    Like

  10. I have a question
    In  my case i am using Wcf Ria enable web site.i am using Domainservice and wcf service in one project. it working fine on my development  machine but when i host this site one IIS. Wcf service method work fine but domainService method throw and error the error is
    System.ServiceModel.DomainServices.Client.OperationBase.Complete(Exception error)
    please advice me
    Thanks in advance
     

    Like

  11. Make sure to uploads all files on web server which are part of ria library.i.e file having Ria in their path should be marked as Copy and should be present in bin folder on your IIS.RIA is wrapper over WCF,which provides dynamic activation and hosting of svc virtual files from domain service classes.Please make sure to launch you svc path instead of your silverlight application to see the actual error.You may search inside generated_code folder which is hidden and is present in your silverlight project for svc files and launch append the svc url to your base url to test your web service

    Like

  12. Hi Rajneesh,
    thanks a lot for this blog. This entry especially solved a lot of my queries. I am deploying a RIA Business app developed with VS 2008 and silverlight 3  into IIS 6.0. I have ran into the much discussed issue of  Load operation failed for query GetUser(). I followed the instructions you have given, and I get past the error message. But now, I am facing another problem. the login credentials (I am using the default ASPNetDB that comes with the RIA services to authenticate users) are not recognised in IIS. it works fine in the development environment. what cloud be wrong here? Please suggest some workarround.
    thanks for your effort.

    Like

  13. Hi Rajneesh,
    I have SQL Server 2005 Express installed as my backend. When I am trying to run aspnet_regsql, it is showing me the server could not be found. Please help.

    Like

    1. Seams that aspnet_regsql is not able to connect your sql server.Make sure to provide correct connection details and instance name. use aspnet_regsql /? to check documentation on several parameters.

      Like

  14. Hi,

    I am getting:
    Load operation failed for query ‘login’ the remote server returned an error NotFound
    I published using VS 2010 and using Silverlight 4 and Ria services.

    I have copied all the required DLLs onto my server and still no luck
    Could you help on solving this issue please?

    I have tried different tricks on the web.config and nothing changed and still getting the same error…

    Thanks

    Like

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s