Solved

Silverlight to WCF. How to configure the service

Posted on 2010-09-14
10
357 Views
Last Modified: 2012-05-10
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
Comment
Question by:jimmysaunders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
10 Comments
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 33675926
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
 

Author Comment

by:jimmysaunders
ID: 33676360
That is not a fix. That's hacking it. I'm looking for the proper way of doing it.
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 33676393
silver light 4 or 3 ?
0
Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 33676442
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
 

Author Comment

by:jimmysaunders
ID: 33676550
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
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 33676683
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
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 33676695
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
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 500 total points
ID: 33676717
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
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 33676752
also dont forget to change the following line to suit your dll/xap

xmlns:conf="clr-namespace:SilverlightApplication1;assembly=SilverlightApplication1"
0
 

Author Comment

by:jimmysaunders
ID: 33677256
Thanks a lot. It worked (not exactly how you did it) but a little variation of it.

Thanks again.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question