Select to view content in your preferred language

need help starting address-to-location computations

724
5
11-11-2010 09:51 AM
SangamLama
Emerging Contributor
Hi there, I have a SL application which speaks to a wcf service. What I'm trying to do is -- I need to find lat/long of about 20 addresses and pin them on the map. All the dirty of work sending requests to arcgis should be done in the wcf side. The only thing SL side does is it calls the wcf function and gets data back, and in turn pins them on the map.

So can someone please please please post a sample link, or an example? It's important that WCF side carries out all the request and processing . And it is also very important that 20 addresses are sent from silverlight side as an input parameter to the wcf function.

I looked at Interactive samples of SL version, but the tutorial does everything in the SL side. And I'm not being able carry out separation of concern here.

Thanks!
0 Kudos
5 Replies
JenniferNery
Esri Regular Contributor
0 Kudos
SangamLama
Emerging Contributor
Have you looked at this blog: http://blogs.esri.com/Dev/blogs/silverlightwpf/archive/2010/03/11/Sending-geometry-between-Silverlig...


I did. Actually, that's what my application is based off of. However, when I do the same thing with the function that calls locatorTask.AddresstoLocation, I have no idea how the SL side can get the data. For instance, where's what I have on wcf,

[OperationContract]
        public void GeocodeAddress(string address, string city, string state, string zip)
        {

            Locator locatorTask = new Locator("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" +
               "Locators/ESRI_Geocode_USA/GeocodeServer");
            locatorTask.AddressToLocationsCompleted += locatorTask_AddressToLocationsCompleted;
            AddressToLocationsParameters addressParams = new AddressToLocationsParameters();
            Dictionary<string, string> fullAddress = addressParams.Address;

            if (!string.IsNullOrEmpty(address))
                fullAddress.Add("Address", address);
            if (!string.IsNullOrEmpty(city))
                fullAddress.Add("City", city);
            if (!string.IsNullOrEmpty(state))
                fullAddress.Add("State", state);
            if (!string.IsNullOrEmpty(zip))
                fullAddress.Add("Zip", zip);

            locatorTask.AddressToLocationsAsync(addressParams);

           
        }


        public void locatorTask_AddressToLocationsCompleted(object sender, AddressToLocationsEventArgs e)
        {
            List<AddressCandidate> geoResponse = e.Results;
         
        }

which I'm assuming is the standard way to setup the request. But how would I call GeocodeAddress function? I mean, I can invoke that function from Silverlight side, but GeocodeAddress() function isn't what returns the data back. It's the callback locatorTask_AddressToLocationsCompleted()..And I have no idea how to communicate with that callback from Silverlight. Things would have been so much easier if AddresstoLocation function was synchronous, but it's not...

Does that elaborate my dilemma?
0 Kudos
JenniferNery
Esri Regular Contributor
0 Kudos
SangamLama
Emerging Contributor
has anybody else done someone like I have over silverlight/wcf? I don't know what's up, but if the Silverlight side sends a request to my wcf service to find location of even a single address, I don't get anything back! and the wcf service times out! In other words, the async function never reaches the callback.

I'd really really really appreciate if someone can provide a working example for this...

thanks, 




This might be what you need http://russelleast.wordpress.com/2010/02/27/using-wcf-async-pattern-with-silverlight-3/

This is from MSDN http://msdn.microsoft.com/en-us/library/ms731177.aspx
0 Kudos
nakulmanocha
Esri Regular Contributor
Here is one way to do this..

----------------
  SL side code
----------------

public MainPage()
        {
            InitializeComponent();
            MyGeometryServiceClient client = new ServiceReference1.MyGeometryServiceClient();
                      
            client.GeocodeAddressAsync("400 Market Street", "San Francisco", "CA", "94111");
            client.GeocodeAddressCompleted += client_GeocodeAddressCompleted;
           
        }

        void client_GeocodeAddressCompleted(object sender, GeocodeAddressCompletedEventArgs e)
        {
            ESRI.ArcGIS.Client.Geometry.Geometry geom = e.Result;
            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
            graphicsLayer.ClearGraphics();

            Graphic graphic = new Graphic()
            {
                Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol,
                Geometry = geom
            };

           
            graphicsLayer.Graphics.Add(graphic);
         
           
        }

--------------
WCF side code
---------------

[ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class MyGeometryService
    {
        private Geometry firstCandGeom;
       
        // Add more operations here and mark them with [OperationContract]
        [OperationContract]
        public Geometry GeocodeAddress(string address, string city, string state, string zip)
        {

            Locator locatorTask = new Locator("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Locators/ESRI_Geocode_USA/GeocodeServer");
            locatorTask.AddressToLocationsCompleted += new EventHandler<AddressToLocationsEventArgs>(locatorTask_AddressToLocationsCompleted);
            locatorTask.Failed += new EventHandler<TaskFailedEventArgs>(locatorTask_Failed);
            AddressToLocationsParameters addressParams = new AddressToLocationsParameters();
            Dictionary<string, string> fullAddress = addressParams.Address;

            if (!string.IsNullOrEmpty(address))
                fullAddress.Add("Address", address);
            if (!string.IsNullOrEmpty(city))
                fullAddress.Add("City", city);
            if (!string.IsNullOrEmpty(state))
                fullAddress.Add("State", state);
            if (!string.IsNullOrEmpty(zip))
                fullAddress.Add("Zip", zip);

          
            locatorTask.AddressToLocationsAsync(addressParams);
            do
            {
                Thread.Sleep(100);

            } while (locatorTask.IsBusy);

           
            return firstCandGeom;

        }

        void locatorTask_Failed(object sender, TaskFailedEventArgs e)
        {
           
        }
        public void locatorTask_AddressToLocationsCompleted(object sender, AddressToLocationsEventArgs e)
        {
            List<AddressCandidate> geoResponse = e.Results;
            AddressCandidate firstCand = geoResponse[0];
            firstCandGeom = firstCand.Location;

        }
    }
0 Kudos