How to solve the security problem of Silverlight cross-origin access

Source: Internet
Author: User

The specific steps are not too detailed. They are nothing more than adding a new WebService file, adding Web references, generating proxy classes, defining methods, and encapsulating third-party services. I am using a weather forecast service.

The following is part of the service code:

The Code is as follows: Copy code

/// <Summary>
/// Summary description for WeatherWebService
/// </Summary>
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)]
[System. ComponentModel. ToolboxItem (false)]
// To allow this Web Service to be called from script, using ASP. net ajax, uncomment the following line.
// [System. Web. Script. Services. ScriptService]
Public class WeatherWebService: System. Web. Services. WebService
{

/// <Summary>
/// Obtain the name of a city in a specified province supported by the third-party ws
/// </Summary>
/// <Param name = "provinceName"> </param>
/// <Returns> </returns>
[WebMethod]
Public string [] GetSupportCity (string provinceName)
{
Var service = new WS. WeatherWebServiceSoapClient ();
Return service. getSupportCity (provinceName );
}
}

Step 2: reference the local service in the SL Project
Directly add a local WebService reference and call it in the program. The following is some code:

The Code is as follows: Copy code

Private void button#click (object sender, RoutedEventArgs e)
{
Var service = new LocalServiceReference. WeatherWebServiceSoapClient ();
Service. GetSupportCityCompleted + = new EventHandler <GetSupportCityCompletedEventArgs> (service_GetSupportCityCompleted );
Service. GetSupportCityAsync ("Anhui ");
}

Void service_GetSupportCityCompleted (object sender, GetSupportCityCompletedEventArgs e)
{
This. ListContent. ItemsSource = e. Result;
} Step 3: view the result

 

First, directly access third-party services:

 

 

This is the result of using the local service as an intermediary:

 

 

Related Article

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.