Select to view content in your preferred language

Call a GP Service in FlexViewer 2.3.1

1921
10
07-05-2011 07:37 AM
francescodi_vito
Deactivated User
Hy guys
i develop a model ain ArcGis 10 and i publish it as a Map Service with a Tool Layer. The GP Service is Synchronus and he works very well. i need to change the GP Service in Asynchronous but i tried to change my script but don't works.
i post here my script for my model synchronus
<?xml version="1.0" encoding="utf-8"?>
<!--
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2010 ESRI
//
// All rights reserved under the copyright laws of the United States.
// You may freely redistribute and use this software, with or
// without modification, provided you include the original copyright
// and use restrictions.  See use restrictions in the file:
// <install location>/License.txt
//
////////////////////////////////////////////////////////////////////////////////
-->
<viewer:BaseWidget xmlns:fx="http://ns.adobe.com/mxml/2009"
       xmlns:s="library://ns.adobe.com/flex/spark"
       xmlns:mx="library://ns.adobe.com/flex/mx"
       xmlns:esri="http://www.esri.com/2008/ags"
       xmlns:viewer="com.esri.viewer.*"
       height="192">
 <fx:Script>
  <![CDATA[
   import com.esri.ags.FeatureSet;
   import com.esri.ags.Graphic;
   import com.esri.ags.SpatialReference;
   import com.esri.ags.events.GeoprocessorEvent;
   import com.esri.ags.events.GraphicsLayerEvent;
   import com.esri.ags.events.MapMouseEvent;
   import com.esri.ags.geometry.Geometry;
   import com.esri.ags.symbols.SimpleFillSymbol;
   import com.esri.ags.symbols.SimpleLineSymbol;
   import com.esri.ags.symbols.SimpleMarkerSymbol;
   import com.esri.ags.tasks.Geoprocessor;
   
   import mx.controls.Alert;
   import mx.rpc.events.FaultEvent;
   
   private function startGeoProcess(event:MouseEvent):void
   {
    
    
    var parms:Object = new Object();
    parms.Condizione = String(condizione.text);
    parms.Valore = Number(valore.text);
    
    
    var geoprocessTask:Geoprocessor = new Geoprocessor();
    geoprocessTask.outSpatialReference = map.spatialReference;
    geoprocessTask.showBusyCursor = true;
    geoprocessTask.url = "http://193.204.163.134/ArcGIS/rest/services/ENEA/Cap_Term_Vol_MAX/GPServer/CapTermVolMAX";
    geoprocessTask.useAMF = false;
    geoprocessTask.execute(parms);
    geoprocessTask.addEventListener(GeoprocessorEvent.EXECUTE_COMPLETE, executeCompleteHandler);
    geoprocessTask.addEventListener(FaultEvent.FAULT, faultHandler);
   }
   
   private function executeCompleteHandler(event:GeoprocessorEvent):void
   {
    
    
    var myPointSymbol:SimpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 12, 0x1AA1D3, 0.3);
    
    
    for each (var graphic:Graphic in event.executeResult.results[0].value.features)
    {
     graphic.symbol = myPointSymbol;
     graphicsLayer.add(graphic);
     map.addLayer(graphicsLayer);
     
    }
   }
   
   private function faultHandler(event:FaultEvent):void
   {
    if (event.type == "fault"
     && event.fault.name == 'Error'
     && event.fault.faultCode == '500'
     && event.fault.faultString == 'Error Executing Task')
    {
     Alert.show("Oops - no results.  Try clicking in an ocean...");
    }
    else
    {
     Alert.show("Unexpected fault:\n" + event.toString());
    }
   }
  ]]>
 </fx:Script>
 
 <fx:Declarations>
  <esri:GraphicsLayer id="graphicsLayer"/>
 </fx:Declarations>
 
 
 <viewer:WidgetTemplate id="helloWorld"
         width="390" height="192">
  
  <s:Label text="RICERCA CAPACITA' TERMICA MIN" y="10" horizontalCenter="0" color="#000000" fontWeight="bold"/>
  
  <s:TextInput id="condizione"
      width="66"
      paddingLeft="0"
      paddingRight="0"
      text="&gt;" y="48" horizontalCenter="0" textAlign="center"/>
  <s:Label text="inserisci valore" y="76" horizontalCenter="0"/>
  <s:Button 
   label="Ricerca" 
   click="startGeoProcess(event)"
   bottom="5" left="10" cornerRadius="7"/>
  <s:Button 
   label="Clear" 
   click="graphicsLayer.clear()"
   bottom="5" right="9" cornerRadius="7"/>
  <s:TextInput id="valore"
      width="66"
      paddingLeft="0"
      paddingRight="0"
      text="2" y="92" horizontalCenter="0" textAlign="center"/>
  <s:Label text="inserisci operatore matematico ( &gt; / &lt; )" y="32" horizontalCenter="0"/>
  
 </viewer:WidgetTemplate>
</viewer:BaseWidget>

can anybody tell me how to modify my script for set my GP Service as Asynchronous?
help please
Thanks
Tags (2)
0 Kudos
10 Replies
YungKaiChin
Regular Contributor
1. Make sure the service support asynchronous geoprocessing ... (it will show in the fault msg)
2. Change execute to submitJob geoprocessTask.submitJob(parms);
3. Change event executeComplete > jobComplete


The reference can be found here:
http://help.arcgis.com/en/webapi/flex/apiref/index.html?com/esri/ags/tasks/JobInfo.html&com/esri/ags...
0 Kudos
IvanBespalov
Frequent Contributor
http://193.204.163.134/ArcGIS/sdk/rest/index.html?gpserver.html - ArcGIS Server REST API

gpService.execute(params, new AsyncResponder(gpServiceResultHandler, gpServiceFaultHandler));

...

private function gpServiceResultHandler(data:Object, token:Object = null):void
{ //do smthing with results }

private function gpServiceFaultHandler(fault:Fault, token:Object = null):
{ //do smthing with faults }


Also in last Flex Viewer from ESRI you can find DataExtractWidget - it works with GPServices.

looking on your service, i cant find "SubmitJob" in supported operations

execute()
submitJob()
0 Kudos
francescodi_vito
Deactivated User
hi
in my service you don't see submitJob because i set it Synchronous. When i tried with submitJob i change the service property.
I try with your help and after i will wrote for the responce
Thanks
0 Kudos
francescodi_vito
Deactivated User
can you give me a link for download the DataExtractWidget?
thanks
0 Kudos
IvanBespalov
Frequent Contributor
0 Kudos
francescodi_vito
Deactivated User
Hi Ivan, thanks.
Now i try the code that you give me and after i say you if it works good
thanks
0 Kudos
IvanBespalov
Frequent Contributor
Hmmm. Now I understood the meaning of your question.
:confused:

"ykchin" advised you how to solve you problem. No more - only 3 steps.

I just tried to show you where you can get help.
0 Kudos
francescodi_vito
Deactivated User
hi Ivan
I followed the instructions of "ykchin" but the model don't get me a result.
private function startGeoProcess(event:MouseEvent):void
   {
    
    
    var parms:Object = new Object();
    parms.Condizione = String(condizione.text);
    parms.Valore = Number(valore.text);
    
    
    var geoprocessTask:Geoprocessor = new Geoprocessor();
    geoprocessTask.outSpatialReference = map.spatialReference;
    geoprocessTask.showBusyCursor = true;
    geoprocessTask.url = "http://193.204.163.134/ArcGIS/rest/services/ENEA/Cap_Term_Vol_MAX/GPServer/CapTermVolMAX";
    geoprocessTask.useAMF = false;
    geoprocessTask.submitJob(parms);
    geoprocessTask.addEventListener(GeoprocessorEvent.JOB_COMPLETE, executeCompleteHandler);
    geoprocessTask.addEventListener(FaultEvent.FAULT, faultHandler);
   }
   
   private function executeCompleteHandler(event:GeoprocessorEvent):void
   {
    
    
    var myPointSymbol:SimpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 10, 0x1AA1D3, 0.2);
    
    
    for each (var graphic:Graphic in event.executeResult.results[0].value.features)
    {
     graphic.symbol = myPointSymbol;
     graphicsLayer.add(graphic);
     map.addLayer(graphicsLayer);
     
    }
   }
   
   private function faultHandler(event:FaultEvent):void
   {
    if (event.type == "fault"
     && event.fault.name == 'Error'
     && event.fault.faultCode == '500'
     && event.fault.faultString == 'Error Executing Task')
    {
     Alert.show("Oops - no results.  Try clicking in an ocean...");
    }
    else
    {
     Alert.show("Unexpected fault:\n" + event.toString());
    }
   }

In your opinion is there a error?
With Synchronous model and the original code that i post, i have a result. But the model takes a long time to run and after 2 mitutes in my application i have a worning by plug-in of ShockWave Flash, because because it's been a long time.
What do you think?
Help
0 Kudos
IvanBespalov
Frequent Contributor
Sorry, but my English is so poor... i can't describe you how to... I tried to give you links to ESRI help.

Just feel the difference between

screen3.png (ESRI sample service) - support asynchronous geoprocessing
and
screen2.png (your service) - NOT support asynchronous geoprocessing
0 Kudos