When deploying a SILVERLIGHT site, you must be able to modify the address of the WCF Service and search for multiple articles online. The program transformation is successful. The process is summarized as follows:
1. Add configuration nodes in WEB. CONFIG
<Deleetask>
<Add key = "WCFServiceAddress" value = "http: // 192.168.100.107/ProspectTaskWcfService/SilverLight_Service.svc"/>
</AppSettings>
2. Add <param name = "initParams" vaule = ""/> On the aspx page of host Silverilght. After adding the parameter, the following figure shows the result:
If we want to upload something to SILVERLIGHT, we can also use this method.
<param name="source" value="ClientBin/Jurassic.ProspectTask.Web.Control.WorkPlan.xap"/><param name="onerror" value="onSilverlightError" /><param name="background" value="white" /><param name="minRuntimeVersion" value="3.0.40624.0" /><param name="autoUpgrade" value="true" /><param name="initParams" value="wcfServiceUrl=<%=ConfigurationManager.AppSettings["WCFServiceAddress"] %> " />
If you want to input multiple parameters in initParams, they can be separated by parameters. For example, keyword a = value a, keyword B = value B
3. In the SilverLight project App. xmal. cs, add the CustomConfigurations attribute and modify the event Application_Startup. As shown below
Private IDictionary <string, string> _ mmtionary ations;
Public IDictionary <string, string> customtionary ations
{
Get {return _ customConfigurations ;}
}
Public App ()
{
This. Startup + = this. Application_Startup;
This. Exit + = this. Application_Exit;
This. UnhandledException + = this. Application_UnhandledException;
InitializeComponent ();
}
Private void Application_Startup (object sender, StartupEventArgs e)
{
_ CustomConfigurations = e. InitParams;
This. RootVisual = new MainPage ();
}
4. Add a new CLASS in the SilverLight project to return a connected instance.
Public class WcfService
{
Public WcfService ()
{
}
Public SilverService. SilverLightClient GetWCF ()
{
App application = (App) Application. Current;
String url = application. CustomConfigurations ["wcfServiceUrl"];
BasicHttpBinding binding = new BasicHttpBinding (BasicHttpSecurityMode. None );
Binding. maxcompute edmessagesize = int. MaxValue;
Binding. MaxBufferSize = int. MaxValue;
//
SilverService. SilverLightClient client = new SilverService. SilverLightClient (binding, new EndpointAddress (new Uri (url )));
Return client;
}
}
When we need to call the WCF Service, we can use the above method to obtain the instance.
WcfService wcf = new WcfService ();
SilverService. SilverLightClient client = wcf. GetWCF ();
Client. UpdatePlanCompleted + = new EventHandler <System. ComponentModel. AsyncCompletedEventArgs> (OnCompleted );
Client. UpdatePlanAsync (_ planEntity );
Article to learn it Network: http://www.xueit.com/html/2011-05/111-7254361172011513153445656.html