Share silverlight modify the configuration file WEB. CONFIG and specify the server address to access WCF

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.