New Posts New Posts RSS Feed: Changing app.config URI after build
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Changing app.config URI after build

 Post Reply Post Reply
Author
amit007 View Drop Down
Newbie
Newbie
Avatar

Joined: 10-Mar-2009
Posts: 10
Post Options Post Options   Quote amit007 Quote  Post ReplyReply Direct Link To This Post Topic: Changing app.config URI after build
    Posted: 02-Feb-2010 at 12:16pm
HI,
I have a silverlight application for that i need to figure it out how to change the app.config uri when i am ready to deploy to client site. Our client will not have a fixed uri, so can't set this in advance.  I try to set the app.config build action to "Content", but it automatically get reset to "Embedded Resource".
 
Thanks,
Amit 
Back to Top
DapperDanH View Drop Down
Newbie
Newbie
Avatar

Joined: 24-Apr-2008
Location: United States
Posts: 10
Post Options Post Options   Quote DapperDanH Quote  Post ReplyReply Direct Link To This Post Posted: 18-Feb-2010 at 8:28am

I can’t find a way to initialize the EntityManager in code and change the URI of the EntityService.  Can anyone provide sample code of programmatically setting up the EntityManager and passing in the URI of the EntityService?

Thanks,
Dan Hickman
Back to Top
JoshO View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Location: United States
Posts: 86
Post Options Post Options   Quote JoshO Quote  Post ReplyReply Direct Link To This Post Posted: 18-Feb-2010 at 12:25pm
I have just finished modifying our Simple Silverlight App from the DevForce Learning Resources. The app will read the object server properties (remoteBaseURL, serverPort, and serviceName) from the web.config. I will place snippets of the changes to be made and I will give a link to download the solution as well. There are no DevForce code changes to be made, this is all ASP.NET and Silverlight code.
Back to Top
DapperDanH View Drop Down
Newbie
Newbie
Avatar

Joined: 24-Apr-2008
Location: United States
Posts: 10
Post Options Post Options   Quote DapperDanH Quote  Post ReplyReply Direct Link To This Post Posted: 18-Feb-2010 at 12:47pm
thanks!  look forward to the snippet.
Back to Top
JoshO View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Location: United States
Posts: 86
Post Options Post Options   Quote JoshO Quote  Post ReplyReply Direct Link To This Post Posted: 18-Feb-2010 at 1:00pm
This is for Silverlight applications that use the <object> element in its startup page. C# is used in the code snippets from the xaml pages (App.xaml and Page.xaml).
 
Sorry about the spacing, pasting from VS is not the best. I will post the download link for this solution in about an hour.
 
First, add an <appSettings> element to your web.config anywhere under <configuration>:

<appSettings>

<add key="RemoteBaseURL" value="http://bobo"/>

<add key="RemoteBasePort" value="9009"/>

<add key="RemoteBaseServiceName" value="EntityService.svc"/>

</appSettings>

 
Next, in your Silverlight startup page (typically default.aspx) add a <param> element named "initParams" as shown below. You assign the key/value pairs from the <appSettings> in the web.config. Separate each pair with a comma ","  .
 

<param name="initParams" value="<%= string.Format("RemoteBaseURL={0}", ConfigurationManager.AppSettings["RemoteBaseURL"])%>,<%= string.Format("RemoteBasePort={0}", ConfigurationManager.AppSettings["RemoteBasePort"])%>,<%= string.Format("RemoteBaseServiceName={0}", ConfigurationManager.AppSettings["RemoteBaseServiceName"])%>" />
 
Next, modify your "Application_Startup" method found in the App.xaml.cs. In this method, you have access to the initParams you created in the default.aspx through the "StartupEventArgs e". For development purposes, I added an "if" statement which will ignore the appSettings in the web.config if your "remoteBaseURL" property in the application's app.config is set to http://localhost so that Visual Studio will run the app under Cassini.
 

private void Application_Startup(object sender, StartupEventArgs e) {

var config = IdeaBlade.Core.IdeaBladeConfig.Instance;

var serverInfo = config.ObjectServer;

if (serverInfo.RemoteBaseUrl != "http://localhost")

{

serverInfo.RemoteBaseUrl = e.InitParams["RemoteBaseURL"];

serverInfo.ServerPort = int.Parse(e.InitParams["RemoteBasePort"]);

serverInfo.ServiceName = e.InitParams["RemoteBaseServiceName"];

}

this.RootVisual = new Page();

}

 
Back to Top
JoshO View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Location: United States
Posts: 86
Post Options Post Options   Quote JoshO Quote  Post ReplyReply Direct Link To This Post Posted: 18-Feb-2010 at 2:17pm
Here is the solution built from DevForce 5.2.5.
 
 
 
NOTE:  if you deploy this sample app to an IIS 7 server, you must either assign the app to the "Classic .NET App Pool" or add this to the web.config:

<system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
 
Finally, the <edmKey> in the web.config is set to connect to a local SQL Server that has the "NorthwindIB" database which is installed with DevForce and the security is set to "Integrated Security=True" which means the IIS Application Pool user account needs access to the SQL Server instance which it shouldn't by default. I would change it to use a SQL user login instead or create a new application pool that runs under a Windows account that you have granted access in SQL Server. Integrated Security works just fine in Cassini since it uses your Windows account which would have access to a local SQL Server instance.


Edited by JoshO - 18-Feb-2010 at 6:28pm
Back to Top
DapperDanH View Drop Down
Newbie
Newbie
Avatar

Joined: 24-Apr-2008
Location: United States
Posts: 10
Post Options Post Options   Quote DapperDanH Quote  Post ReplyReply Direct Link To This Post Posted: 23-Feb-2010 at 6:18am

It’s interesting that you recommend using InitParams. We debated the asp.net InitParams approach versus silverlight code-behind  leveraging DocumentURI.Host and DocumentURI.Port.

 
My guess is if your webservice is hosted on a different server from your asp/Silverlight application, you’d want to configure the initparam way.
 
Thoughts?
 
Dan

Back to Top
JoshO View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Location: United States
Posts: 86
Post Options Post Options   Quote JoshO Quote  Post ReplyReply Direct Link To This Post Posted: 24-Feb-2010 at 11:50am
Actually, I am the IT guy here Ideablade and I chose to place my configuration settings in the web.config since that is where I would hope to find them during deployment. Several Google searches led me to "InitParams" and how to pass it to a Silverlight app. I don't know the "why" of what I did other than it worked and seemed to follow the normal practices of web apps even though it may not be the "best practice". One of our best developers here gave me an answer to your question:
 
"I haven’t used DocumentUri, but you can also do it using the Silverlight Application.Current.Host.Source value something like this:

      var cfg = IdeaBladeConfig.Instance;

      var src = System.Windows.Application.Current.Host.Source;

      string url = string.Format("{0}://{1}", src.Scheme, src.Host);

      cfg.ObjectServer = new ObjectServerElement() {

        IsDistributed = true, RemoteBaseUrl = url, ServiceName = "EntityService.svc",

        ServerPort = src.Port

      };

Using InitParams, or Application.Current, or DocumentUri, is mostly a matter of taste and what you need.
InitParams has the advantage of 1) supporting a BOS not at the same site as the XAP, and 2) is also a good flexible approach to passing arguments into the Silverlight application."
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down