Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 370
  • Last Modified:

Silverlight to WCF. How to configure the service

I have a Silverlight application that has a reference to a WCF service which acts as the data layer. It's all working fine but when I think about deploying it to production, I can't just copy the folders to the production because I the App would still be pointing to the WCF service on the other server. I looked but there is no option to have a config type thing that used to be there for asmx services. How is the reference is changes to point to the other server without compiling the code?

Thanks.
0
jimmysaunders
Asked:
jimmysaunders
  • 7
  • 3
1 Solution
 
Gautham JanardhanCommented:
The fix is simple, but annoying: when you deploy, you  have to unzip the .xap package, manually edit the .clientConfig to correct the address, then zip the .xap file back up.
0
 
jimmysaundersAuthor Commented:
That is not a fix. That's hacking it. I'm looking for the proper way of doing it.
0
 
Gautham JanardhanCommented:
silver light 4 or 3 ?
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
Gautham JanardhanCommented:
if 3... you can add a xaml/xml  file which will hold your configuration(mainly end point and any other config you need for you silver light application) to the root web site folder (i prefer xaml mainly because i convert it into an object using xaml loader) and then when the silver light application starts up, download it and read the end points and set it to the service client.

if 4 -> http://msdn.microsoft.com/en-us/library/cc197941(v=VS.95).aspx
0
 
jimmysaundersAuthor Commented:
It's Silverlight 3.

How do I do what you wrote in the last i.e. set the end point to the service client. I would appreciate a code snippet if possible.

Thanks.
0
 
Gautham JanardhanCommented:
in the app.xaml.cs file

the Application_Startup would change as shown below



private void Application_Startup(object sender, StartupEventArgs e)
        {
            WebClient client = new WebClient();
            client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
            client.DownloadStringAsync(new Uri("/config.xaml",UriKind.Relative));
        }

Open in new window

0
 
Gautham JanardhanCommented:
and the call back
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            Config config = (Config)XamlReader.Load(e.Result); // u can cache it as a singleton to use in other parts of the application
            ServiceReference.MessagingHelloClient client = new SilverlightApplication1.ServiceReference.MessagingHelloClient();
            client.Endpoint.Address = new System.ServiceModel.EndpointAddress(config.Endpoint); // just a sample on how to set the end point
            this.RootVisual = new MainPage();
        }

Open in new window

0
 
Gautham JanardhanCommented:
the xaml config file to be copied to the root folder (u can copy it any where in the webs server just need to give path appropriately when downloading)

also you can extent this config file to add any configuration required by your application
<conf:Config    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                            xmlns:conf="clr-namespace:SilverlightApplication1;assembly=SilverlightApplication1"
                            xmlns:sys='clr-namespace:System;assembly=mscorlib' Endpoint='http://localhost:5000/MyService.svc'>
</conf:Config>

Open in new window

0
 
Gautham JanardhanCommented:
also dont forget to change the following line to suit your dll/xap

xmlns:conf="clr-namespace:SilverlightApplication1;assembly=SilverlightApplication1"
0
 
jimmysaundersAuthor Commented:
Thanks a lot. It worked (not exactly how you did it) but a little variation of it.

Thanks again.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now