Search code examples
c#silverlight-4.0webservices-client

Accessing SOAP web service from Silverlight 4 client


I am doing a proof of concept where I access a public web service from my Silverlight 4 client application. When I attempt to make the call this sample public web service, I get the following error:

An error occurred while trying to make a request to URI 'http://www.w3schools.com/webservices/tempconvert.asmx'. 
This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, 
or a policy that is unsuitable for SOAP services. 
You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. 
This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. Please see the inner exception for more details.

Can I only access web services which have these policies in place or am I simply not configuring my ASMX service correctly in my project? The code to call the service is as follows:

   // Create
    var webServiceProxy = new TempConvert.TempConvertSoapClient();

    // Delegate
    webServiceProxy.FahrenheitToCelsiusCompleted += (s, args) =>
    {
        // Fail?
        if (args.Error != null)
        {
            // Message
            MessageBox.Show(string.Format("Something went wrong!\n\n{0}", args.Error.Message));
        }
        else
        {
            // Message
            MessageBox.Show(string.Format("50 f to c is {0}.", args.Result));
        }
    };

    // Call
    webServiceProxy.FahrenheitToCelsiusAsync("50");

Solution

  • Most likely if you're running this from your machine, you're crossing domain boundaries and require the called site to have the policies in place to call from a different domain.

    Microsoft has plenty of information about it, also look up 'silverlight cross domain' for more information.