locked
One WCF Service, three connection strings RRS feed

  • Question


  • Hello, I have created a WCF Data Service, with EF4 and VS2010.
    I have created a Silverlight application to use it, it works.

    A new need arise, I need to host the data on three environments, LOCAL, INTRANET and AZURE so the user can choose from the UI, what datasource to use.

    I saw some articles on the net, proposing to create several end points or overloading a method, but I could not find what to overload in my application.

    About creating several end points, I couldn't see how to do that.  I have my EDMX file, my WCF Data service with code to add logic, should I duplicate the logic for each end points and provide different connection strings to each end point ?

    I would have liked a solution where the client, an SL4 application fills a parameter to decide what environment to use like below, is there any ways to do that ?  

    <riaControls:DomainDataSource.DomainContext>
    <my:MyServiceDomainContext Options="" />
    </riaControls:DomainDataSource.DomainContext>

    If not, if I need to use the approach with several service end points, how to choose one from my client application ?


    Thanks for any help, 
    Claude
    Monday, September 3, 2012 3:55 PM

Answers

All replies

  • Hi !!!

    I went back and looked at the overriding (not overloading as I was saying...) solution, based on this link: http://wildermuth.com/2008/12/16/ADO_NET_Data_Services_for_Multiple_Databases.

    But, this link is about classes that inherits from "DataService" and mine inherits from "LinqToEntitiesDomainService", probably because it is base on EF4, this part is not clear for me, how this code generates.    ( Oh! it might be because it is not a WCF Data Service but a WCF RIA Service, as I understood from this link (http://blog.tallan.com/2012/02/19/wcf-data-services-vs-wcf-ria-services-%E2%80%93-making-the-right-choice/)  :-))

    So, I have found this link: "http://thegrayzone.co.uk/blog/2010/06/dynamically-alter-entityframework-connectionstring-in-domain-service/" that explains which method to override : 

    public class MyDomainService : LinqToEntitiesDomainService<MyEntities>
    {
    protected override MyEntities CreateObjectContext()
    {
    string sHint = System.Web.HttpContext.Current.Request.QueryString["ds"];

    string sConnString = string.format("...{0}...", sHint);

    return new MyEntities(sConnString);

    }

    }

    Except that this line about the querystring is not working.  The current request, in my scenario is the URL to the service 'http///MyService.svc' and I was expecting the current URL in the browser, the url to my xaml page !!

    So, I have found a bit, but how can I pass information from my XAML page to this class in my DataService ??  HttpContext is not accessible from SL4 and I couldn't find an OnInit event on a XAML page.

    I am lost again, please help !!  :-)

    Many thanks,

    Claude


    Monday, September 3, 2012 9:26 PM
  • From your code, is it WCF RIA Service? Have you tried this forum? http://forums.silverlight.net/53.aspx
    • Marked as answer by Claude Vernier Wednesday, September 5, 2012 5:44 AM
    Wednesday, September 5, 2012 2:11 AM
  • You are right, thank you, I should have move there.
    Wednesday, September 5, 2012 5:45 AM