Search code examples
c#google-apiclientaccesspolicy.xml

clientaccesspolicy.xml Not Found 404 in Fiddler


I am working on using Google's GeoCode API to return lat/long values of an address that a user enters in a search box. My code seems to be correct, but I am getting a security exception issue. And when I use Fiddler to check the call I can see the call being sent, but there is a problem with clientaccesspolicy.xml.

It seems as though my WPF application requires Google to have a clientaccesspolicy.xml but Google doesn't have one. So I may need to proxy to make this call to Google's API. Any ideas or work arounds?

code

private void RequestResponseHandler(IAsyncResult asyncResult)
{
    HttpWebResponse response = null;
    Stream responseStream = null;
    try
    {
        response = (HttpWebResponse)request.EndGetResponse(asyncResult);
        responseStream = response.GetResponseStream();
        var xdoc = XDocument.Load(responseStream);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

Fiddler enter image description here enter image description here


Solution

  • As far as I understand, you use this code in a Silverlight application that is pretty picky about cross domain requests. Before perform any request Silverlight runtime tries to find clientaccesspolicy.xml on the target server (in your case maps.googleapis.com) and if it fails, it tries to find crossdomain.xml. Apparently, the server does not have such files and because of that the runtime throws SecurityException.

    As a workaround you can proxy requests to Google Maps API:

    • Your Silverlight application sends a request to the server that hosts that app (and corresponding clienataccesspolicy.xml)
    • Your web server accept request and re-send it to Google API and then returns API's response to your application.