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);
}
}
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 findcrossdomain.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: