locked
GeoLocation Codes from Google Map API RRS feed

  • Question

  • Hi

    I am using below code to get Geo Location codes for an Address in Dynamics CRM. If I run this code in Console App on my IFD enabled server it works. I put this function in Custom Workflow to run against multiple records and update geo codes but it throws an error "Unable to connect to the remote server." Any thoughts why it works in Console App on same server and failed in Custom Workflow?

    private string[] getGeoLocations(string Address)
            {
                string[] resuts = new string[] { "0", "0" };
                string url = "http://maps.googleapis.com/maps/api/geocode/" + "xml?address=" + Address + "&sensor=false";
                WebResponse response = null;
                try
                {
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                    request.Method = "GET";
                    response = request.GetResponse();
                    if (response != null)
                    {
                        XPathDocument document = new XPathDocument(response.GetResponseStream());
                        XPathNavigator navigator = document.CreateNavigator();
                        // get response status 
                        XPathNodeIterator statusIterator = navigator.Select("/GeocodeResponse/status");
                        while (statusIterator.MoveNext())
                        {
                            if (statusIterator.Current.Value != "OK")
                            {
                                 return resuts;
                            }
                        }
                        // get results 
                        XPathNodeIterator resultIterator = navigator.Select("/GeocodeResponse/result");
                        if (resultIterator.MoveNext())
                        {
                            XPathNodeIterator geometryIterator = resultIterator.Current.Select("geometry");
                            if (geometryIterator.MoveNext())
                            {
                                XPathNodeIterator locationIterator = geometryIterator.Current.Select("location");
                                if (locationIterator.MoveNext())
                                {
                                    XPathNodeIterator latIterator = locationIterator.Current.Select("lat");
                                    if (latIterator.MoveNext())
                                    {
                                        resuts[0] = latIterator.Current.Value;
                                    }
                                    XPathNodeIterator lngIterator = locationIterator.Current.Select("lng");
                                    if (lngIterator.MoveNext())
                                    {
                                        resuts[1] = lngIterator.Current.Value;
                                    }
                                }
                            }
                        }
                    }
    
                    return resuts;
                }
                catch (Exception ex)
                {
                    throw new InvalidPluginExecutionException("Error in getting GeoLocation using Google Map API [" + ex.Message + "]" + ex.StackTrace, ex);
                }
    


    Tuesday, July 1, 2014 2:25 AM

All replies

  • Hi,

    did you try to debug the workflow? has the CRM server an internet connection?

    Bye

    Alessandro Graps


    Alessandro Graps

    Tuesday, July 1, 2014 7:44 AM
  • When I try to debug, it throws exception Unable to connect to the remote server.

    Yes server has internet connection. The console App with same code works fine in that server.

    Wednesday, July 2, 2014 12:58 AM
  • If you are running this Plug-in as Sandboxed, there are some limitations by default on the Outbound URI pattern (View this link: http://msdn.microsoft.com/en-us/library/gg334752.aspx):

     These default Web access restrictions are defined in a registry key on the server running the Microsoft.Crm.Sandbox.HostService.exe process. The value of the registry key can be changed by the System Administrator according to business and security needs. The registry key path on the server is:
        HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSCRM\SandboxWorkerOutboundUriPattern
        The key value is a regular expression string that defines the Web access restrictions. The default key value is:
        "^http[s]?://(?!((localhost[:/])|([.*])|([0-9]+[:/])|(0x[0-9a-f]+[:/])|(((([0-9]+)|(0x[0-9A-F]+)).){3}(([0-9]+)|(0x[0-9A-F]+))[:/]))).+";

        By changing this registry key value, you can alter the allowed Web access for sandboxed plug-ins.

    you can visit this link : http://blogs.msdn.com/b/devkeydet/archive/2012/06/14/geocoding-and-displaying-a-map-for-an-address-in-crm-2011.aspx


    Alessandro Graps

    Wednesday, July 2, 2014 7:08 AM
  • It is an on-premise IFD environment. the workflow is not on Sandbox.
    Friday, July 4, 2014 3:16 AM