RIA Services - Url Custumization

Oscar Brito

References:
http://sandrinodimattia.net/blog/post/Things-you-can-do-with-WCF-RIA-Services-and-a-regular-svc-file.aspx
http://weblogs.asp.net/fredriknormen/archive/2009/11/27/wcf-ria-services-binding-deep-dive.aspx

1. If yout do not want default namespace based url, on main web.config file remove the DomainServiceHttpModule from <httpModules> and <system.webServer><modules>.
Example:
<system.webServer>
   <modules runAllManagedModulesForAllRequests="true">
      <!--<add name="DomainServiceModule" preCondition="managedHandler"
        type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" 
           />-->
    </modules>
</system.webServer>
2. Then Create your svc file with content like:
<%@ ServiceHost 
                Service="namespace.riaService"
                Factory="System.ServiceModel.DomainServices.Hosting.DomainServiceHostFactory, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                %>
Remark: Factory must have a full type name!

3. Don't forget the serialization:

<configSections>
    <sectionGroup name="system.serviceModel">
      <section name="domainServices" type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </sectionGroup>
</configSections>
...
 <domainServices>
      <endpoints>
        <clear />
         <add name="odata" type="System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory, System.ServiceModel.DomainServices.Hosting.OData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add name="JSON"
                 type="Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting" />
      </endpoints>
</domainServices>

In this case only json and odata serialization is allowed!
4. test the urls like 
http://localhost.ubisign.local/webservices/Service.svc/json/method
http://localhost.ubisign.local/webservices/Service.svc/oData/ChannelSet
http://localhost.ubisign.local/namespace-Service.svc (does not exists!)

Done!



Visit www.divhide.com for more informations, contacts and news about Web Development.
See other blog posts at blog.divhide.com.



Divhide purpose is to follow the HTML5 movement and contribute with applications which prove the quality of technology.


Feel free to contact divhide.