Use Bing Maps SOAP Services in Flex API

1988
7
Jump to solution
03-20-2012 01:18 PM
ChrisAult
New Contributor
I'm looking for a way to use Bing Maps SOAP services (http://msdn.microsoft.com/en-us/library/cc980922.aspx) from within Flex. Specifically, I'd like to use the Search service. (I know this can all be done in ArcGIS but this decision is out of my hands).

I know that Flex supports SOAP, but I can't find any SDK or documentation for anything other than C#/VB. Even basic SOAP calls aren't very well documented. Has anyone ever tried something like this? Any ideas?

thanks

chris
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Chris,

   That is not to hard. All you do is take the SOAP Address and give that to the Flash Builder "Connect to Data/Service" wizard in the data menu, choose Web Service, next. Then enter "http://dev.virtualearth.net/webservices/v1/searchservice/searchservice.svc?wsdl".

I would name the Service Name: BINGsearchservice and Data type package: BINGvalueObjects.

Once you do that here is a VERY simplified app:

<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"                 xmlns:s="library://ns.adobe.com/flex/spark"                 xmlns:mx="library://ns.adobe.com/flex/mx"                minWidth="955" minHeight="600"                creationComplete="application1_creationCompleteHandler(event)">     <fx:Script>         <![CDATA[             import mx.collections.ArrayCollection;             import mx.controls.Alert;             import mx.events.FlexEvent;             import mx.rpc.events.FaultEvent;             import mx.rpc.events.ResultEvent;             import mx.rpc.soap.WebService;                          import services.bingsearchservice.BINGsearchservice;                          import valueObjects.Credentials;             import valueObjects.FilterExpressionBase;             import valueObjects.SearchOptions;             import valueObjects.SearchRequest;             import valueObjects.SearchResponse;                          protected function application1_creationCompleteHandler(event:FlexEvent):void             {                 var BingSS:BINGsearchservice = new BINGsearchservice();                 var sr:SearchRequest = new SearchRequest();                 sr.Query = "restaurant in Seattle, WA";                 var so:SearchOptions = new SearchOptions();                 var creds:Credentials = new Credentials();                 creds.ApplicationId = "YOUR BING KEY";                 sr._Credentials = creds;                 BingSS.Search(sr);                 BingSS.addEventListener(ResultEvent.RESULT, bingResultHandler);                 BingSS.addEventListener(FaultEvent.FAULT, bingFaultHandler);             }                          public function bingResultHandler(event:mx.rpc.events.ResultEvent):void              {                 var searchResponse:SearchResponse = event.result as SearchResponse;                                  var resultList:String = "";                 for (var i:int=0; i < searchResponse.ResultSets[0].Results.length; i++)                 {                     resultList += searchResponse.ResultSets[0].Results.Name + "\n";                 }                 Alert.show(resultList);             }                          public function bingFaultHandler(event:mx.rpc.events.FaultEvent):void              {                 Alert.show(event.fault.faultDetail,event.fault.name);             }         ]]>     </fx:Script> </s:Application>


Don't forget to click the Mark as answer check on this post and to click the top arrow (promote) as shown below:

View solution in original post

0 Kudos
7 Replies
RobertScheitlin__GISP
MVP Emeritus
Chris,

   That is not to hard. All you do is take the SOAP Address and give that to the Flash Builder "Connect to Data/Service" wizard in the data menu, choose Web Service, next. Then enter "http://dev.virtualearth.net/webservices/v1/searchservice/searchservice.svc?wsdl".

I would name the Service Name: BINGsearchservice and Data type package: BINGvalueObjects.

Once you do that here is a VERY simplified app:

<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"                 xmlns:s="library://ns.adobe.com/flex/spark"                 xmlns:mx="library://ns.adobe.com/flex/mx"                minWidth="955" minHeight="600"                creationComplete="application1_creationCompleteHandler(event)">     <fx:Script>         <![CDATA[             import mx.collections.ArrayCollection;             import mx.controls.Alert;             import mx.events.FlexEvent;             import mx.rpc.events.FaultEvent;             import mx.rpc.events.ResultEvent;             import mx.rpc.soap.WebService;                          import services.bingsearchservice.BINGsearchservice;                          import valueObjects.Credentials;             import valueObjects.FilterExpressionBase;             import valueObjects.SearchOptions;             import valueObjects.SearchRequest;             import valueObjects.SearchResponse;                          protected function application1_creationCompleteHandler(event:FlexEvent):void             {                 var BingSS:BINGsearchservice = new BINGsearchservice();                 var sr:SearchRequest = new SearchRequest();                 sr.Query = "restaurant in Seattle, WA";                 var so:SearchOptions = new SearchOptions();                 var creds:Credentials = new Credentials();                 creds.ApplicationId = "YOUR BING KEY";                 sr._Credentials = creds;                 BingSS.Search(sr);                 BingSS.addEventListener(ResultEvent.RESULT, bingResultHandler);                 BingSS.addEventListener(FaultEvent.FAULT, bingFaultHandler);             }                          public function bingResultHandler(event:mx.rpc.events.ResultEvent):void              {                 var searchResponse:SearchResponse = event.result as SearchResponse;                                  var resultList:String = "";                 for (var i:int=0; i < searchResponse.ResultSets[0].Results.length; i++)                 {                     resultList += searchResponse.ResultSets[0].Results.Name + "\n";                 }                 Alert.show(resultList);             }                          public function bingFaultHandler(event:mx.rpc.events.FaultEvent):void              {                 Alert.show(event.fault.faultDetail,event.fault.name);             }         ]]>     </fx:Script> </s:Application>


Don't forget to click the Mark as answer check on this post and to click the top arrow (promote) as shown below:

0 Kudos
ChrisAult
New Contributor
Hi Robert,

Thanks so much for your help! I tried out this sample with my bing key and it seems to be working. I think I can take it from here.

You've just saved me a ton of time!

thanks,

chris
0 Kudos
PrasannaGovindan1
New Contributor II

Hi Robert, Chris,


wsdl.jpg

I am looking for a way to use WSDL ( SOAP Service) in my ArcGIS Flex application using Flash Builder deveopment. I am trying to show the data from the WSDL in the SEARCH Widget. I dont know how to add and where to add, i know there is a way to add soap connection in the flash builder for ARCGIS FLEX API, but dont know where to add and how to make it work.

Any help would be greatly appreciated.

Thanks,
prasan.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Prasan,

  Using a web service in Flex is actually very easy. I always configure it manually (though there is an automated way that I am not familiar with).

Example snippet:

               private var webService:WebService;

               webService = new WebService();

               webService.wsdl="your wdl URL";

               webService.Search.addEventListener(ResultEvent.RESULT, search_result);

               webService.Search.resultFormat = "object";

               webService.loadWSDL();

               webService.Search.addEventListener(FaultEvent.FAULT, search_fault);

              private function search_result(evt:ResultEvent):void

              {

                    var pRslt:Object = evt.result;

                    if(!pRslt.results.length){

                        return;

                    }

                    dataGrid.dataProvider = pRslt.results;

              }

Notice the .Search after the webService, that is the name of the function in my web service.

PrasannaGovindan1
New Contributor II

Hi Robert,

Thanks a lot for the code. I really apprecaite it. I have couple of questions regarding. As I am not a developer and I only know how to use the FLEX API on XML level, I need to understand certain things,.

1. Shall I add this search_result function in SearchWidget.mxml ?

2. What if I have the wsdl file (shown in my previous thread picture) instead of URL and it has to be triggered everytime when I Search a feature using the search widget, shall I give the path to wsdl file in webservice.wsdl="your wsdl URL".?

3. How does the funtion recognize the data structure in the WSDL file.?

Looking forward to hear from you,

Thanks again,

Prasan

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Prasan,

   This is probably going to be a pretty hard task for you to tackle then if you have no Flex programming experience.

  1. Yes the search_result function and the webService block would go in your widgets mxml file.
  2. If you have wsdl then you should have a web service that this wsdl represents running on a web server, so you need to get that URL.
  3. You have to have a good understanding of the web services operations (callable function) (i.e SI_GIS_ECC in your webservice) and you call that operation from your webService.SI_GIS_ECC(your input parameters if any);

I can make out much from your screenshot as the xml is not formatted. But you or who ever created the web service would know what the inputs and outputs would be.

PrasannaGovindan1
New Contributor II

Hi Robert,

Than you so much for the help. I'll work with a flex developer on your code. Much appreciated.

Thanks again,

Prasan.

0 Kudos