Error when using print service on dynamic layer

3953
15
07-17-2012 04:07 PM
GerardoArmendariz
New Contributor III
I am trying to get my application to use the new PrintTask.

When I try to print the current extent with a ArcGISDynamicMapServiceLayer, I get the following error:

Unable to complete operation.


Anyone out there who have successfully used the PrintTask with a dynamic layer?
Tags (2)
0 Kudos
15 Replies
SchoppMatthieu
New Contributor III
Hi,

Just reproduce the code from this sample into your project:

http://resources.arcgis.com/en/help/flex-api/samples/index.html#/Printing_with_Flex/01nq0000005m0000...

--------------------

These links explain how to publish your own printing service using your own templates:

http://resources.arcgis.com/en/help/main/10.1/index.html#//00570000009s000000
http://video.esri.com/watch/1058/arcgis-for-server-10.1-printingtools-service-tutorial

--------------------

I've got it working the first time.
0 Kudos
GerardoArmendariz
New Contributor III
Actually, all I am doing is working with this sample code below.  The code works as expected.

But, when I add my dynamic layer ( ArcGISDynamicMapServiceLayer ) under the ArcGISTiledMapServiceLayer, I get the error message:
Unable to complete operation.



<?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:esri="http://www.esri.com/2008/ags"
      xmlns:flash="flash.text.*"
      initialize="printTask.getServiceInfo()"
      pageTitle="High-quality printing">
 <fx:Script>
  <![CDATA[
   import com.esri.ags.events.PrintEvent;
   import com.esri.ags.tasks.supportClasses.DataFile;
   import com.esri.ags.tasks.supportClasses.JobInfo;
   import com.esri.ags.tasks.supportClasses.ParameterValue;
   import com.esri.ags.tasks.supportClasses.PrintServiceInfo;
   
   import mx.controls.Alert;
   
   private function printBtn_clickHandler(event:MouseEvent):void
   {
    if (printTask.getServiceInfoLastResult.isServiceAsynchronous)
    {
     printTask.submitJob(printParameters);
    }
    else
    {
     printTask.execute(printParameters);
    }
   }
   
   private function printTask_jobCompleteHandler(event:PrintEvent):void
   {
    var jobInfo:JobInfo = event.jobInfo;
    if (jobInfo.jobStatus == JobInfo.STATUS_SUCCEEDED
     && printTask.getServiceInfoLastResult.hasResultData)
    {
     printTask.getResultData(jobInfo.jobId);
    }
    else
    {
     Alert.show(jobInfo.jobStatus);
    }
   }
   
   private function printTask_getResultDataCompleteHandler(event:PrintEvent):void
   {
    var dataFile:DataFile = event.parameterValue.value as DataFile;
    if (dataFile)
    {
     navigateToURL(new URLRequest(dataFile.url));
    }
   }
   
   private function printTask_executeCompleteHandler(event:PrintEvent):void
   {
    if (event.executeResult.results && event.executeResult.results.length > 0)
    {
     var paramValue:ParameterValue = event.executeResult.results[0];
     var dataFile:DataFile = paramValue.value as DataFile;
     if (dataFile)
     {
      navigateToURL(new URLRequest(dataFile.url));
     }
    }
   }
   
   protected function printTask_getServiceInfoCompleteHandler(event:PrintEvent):void
   {
    var printServiceInfo:PrintServiceInfo = event.serviceInfo;
    layoutTemplates.dataProvider = printServiceInfo.layoutTemplates;
    
    for (var i:int = 0; i < layoutTemplates.dataProvider.length; i++)
    {
     var currentItem:String = layoutTemplates.dataProvider.getItemAt(i) as String;
     if (currentItem == "A4 Landscape")
     {
      layoutTemplates.selectedIndex = i;
     }
    }
   }
  ]]>
 </fx:Script>
 
 <fx:Declarations>
  <esri:PrintTask id="printTask"
      executeComplete="printTask_executeCompleteHandler(event)"
      fault="Alert.show(event.fault.faultString)"
      getResultDataComplete="printTask_getResultDataCompleteHandler(event)"
      getServiceInfoComplete="printTask_getServiceInfoCompleteHandler(event)"
      jobComplete="printTask_jobCompleteHandler(event)"
      showBusyCursor="true"
      url="http://apps.tucson.ars.ag.gov:6080/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task"/>
  <esri:PrintParameters id="printParameters"
         format="{formats.selectedItem}"
         layoutTemplate="{layoutTemplates.selectedItem}"
         map="{map}">
   <esri:layoutOptions>
    <esri:LayoutOptions author="Author: ArcGIS for Flex Team"
         copyright="Copyright: © ArcGIS for Server"
         title="My Map"/>
   </esri:layoutOptions>
  </esri:PrintParameters>
  <esri:SimpleLineSymbol id="sls" color="0x999999"/>
  <esri:SimpleMarkerSymbol id="sms0"
         color="0xF8FF09"
         outline="{sls}"
         size="7"
         style="circle"/>
  <esri:SimpleMarkerSymbol id="sms1"
         color="0xEF8F2D"
         outline="{sls}"
         size="8"
         style="circle"/>
  <esri:SimpleMarkerSymbol id="sms2"
         color="0xEA371A"
         outline="{sls}"
         size="9"
         style="circle"/>
  <esri:SimpleMarkerSymbol id="sms3"
         color="0xE9000F"
         outline="{sls}"
         size="12"
         style="circle"/>
  
  <esri:SimpleMarkerSymbol id="g1SMS"
         color="0x660033"
         outline="{sls}"
         size="30"
         style="diamond"/>
  <esri:PictureMarkerSymbol id="g2PMS"
          width="32" height="32"
          source="http://static.arcgis.com/images/Symbols/Basic/GreenShinyPin.png"
          xoffset="2.67"
          yoffset="10.67"/>
  <esri:SimpleFillSymbol id="g3SFS"
          alpha="0.7"
          color="0xCC0000"
          outline="{sls}"/>
  <esri:TextSymbol id="g4TS"
       background="true"
       backgroundColor="0x0000FF"
       border="true"
       borderColor="0x0066FF"
       color="0xCCCCCC"
       placement="above"
       text="Hawaiian Islands"
       xoffset="0"
       yoffset="9">
   <flash:TextFormat bold="true"
         font="Verdana"
         italic="false"
         size="10"
         underline="false"/>
  </esri:TextSymbol>
  <esri:CartographicLineSymbol id="g5CLS"
          width="8"
          alpha="1"
          cap="butt"
          color="0x006633"
          join="miter"
          style="solid"/>
 </fx:Declarations>
 
 <s:controlBarLayout>
  <s:HorizontalLayout gap="10"
       paddingBottom="7"
       paddingLeft="10"
       paddingRight="10"
       paddingTop="7"
       verticalAlign="baseline"/>
 </s:controlBarLayout>
 <s:controlBarContent>
  <s:Label text="Layout Templates"/>
  <s:DropDownList id="layoutTemplates"
      width="175"
      requireSelection="true"/>
  <s:Label text="Formats"/>
  <s:DropDownList id="formats"
      width="100"
      dataProvider="{printTask.getServiceInfoLastResult.formats}"
      requireSelection="true"/>
  <s:Button id="printBtn"
      click="printBtn_clickHandler(event)"
      enabled="{printTask.getServiceInfoLastResult != null}"
      label="Export Map"/>
 </s:controlBarContent>
 
 <esri:Map id="map"
     level="2"
     wrapAround180="true">
  <esri:extent>
   <esri:Extent xmin="-22453200" ymin="-6080645" xmax="3767758" ymax="14465628">
    <esri:SpatialReference wkid="102100"/>
   </esri:Extent>
  </esri:extent>
  <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer"/>
 </esri:Map>
</s:Application>
0 Kudos
GerardoArmendariz
New Contributor III
I have not been able to solve this problem with PrintTask.

I have also tried the suggestions about "sleeping server": http://forums.arcgis.com/threads/26850-Sleeping-Server-Services-slow-to-start?highlight=Flex+Sleepin...

I have also tried building my own ExportWebMap GP service: http://resources.arcgis.com/en/help/main/10.1/index.html#//00570000009s000000

This is the exact message that I get when I run the "Export Map" service:

[ATTACH=CONFIG]16267[/ATTACH]

I am running out of possibilities.  Anyone has encountered this problem?
0 Kudos
DasaPaddock
Esri Regular Contributor
Make sure the machine at apps.tucson.ars.ag.gov can talk to your dynamic map service.

Also, if you use a tool like HttpFox, you can copy the Web_Map_as_JSON request parameter and paste it here.
0 Kudos
GerardoArmendariz
New Contributor III
Dasa, thanks for your response. 

The dynamic service is actually being hosted in this machine. 

I did try your suggestion and debugged with HttpFox.  I still get the same error message:
[ATTACH=CONFIG]16288[/ATTACH]

Would this have anything to do with the Web Adaptor setup?  I have the IIS version installed. 

Any thoughts?


Make sure the machine at apps.tucson.ars.ag.gov can talk to your dynamic map service.

Also, if you use a tool like HttpFox, you can copy the Web_Map_as_JSON request parameter and paste it here.
0 Kudos
DasaPaddock
Esri Regular Contributor
Can you share the contents of the Web_Map_as_JSON request parameter?
0 Kudos
GerardoArmendariz
New Contributor III
Here it is:
{
    "mapOptions": {
        "extent": {
  "xmin": 491821.60721380572,
  "ymin": 3436914.170079994,
  "xmax": 657345.27159446781,
  "ymax": 3602437.8344606562,
  "spatialReference": {
   "wkid": 32612,
   "latestWkid": 32612
  }
 },
        "scale": 1563999.9999999998,
        "spatialReference": {
            "wkid": 32612}
    },
    "operationalLayers": [ ],
    "baseMap": {
        "title": "My Basemap",
        "baseMapLayers": [
            {
                "url": "http://apps.tucson.ars.ag.gov/arcgis/rest/services/dap/DAPSites/MapServer"
            }
        ]
    },
    "exportOptions": {
        "dpi": 100,
        "outputSize": [
            500,
            500
        ]
    }
}


Can you share the contents of the Web_Map_as_JSON request parameter?
0 Kudos
GerardoArmendariz
New Contributor III
Interestingly enough, I tried running Export Map using an Export Service setup by ESRI and it does work:http://servicesbeta4.esri.com/arcgis/rest/services/Utilities/ExportWebMap/GPServer/Export%20Web%20Ma...

Why doesn't this work with my own Export Service?
0 Kudos
DasaPaddock
Esri Regular Contributor
Is it possible that your export service isn't able to connect to http://apps.tucson.ars.ag.gov/arcgis/rest/services/dap/DAPSites/MapServer? Maybe a DNS or firewall issue?

I'm curios where this JSON is coming from too since it doesn't look like it's from the PrintTask. I don't think that's the issue though since it does work from Esri hosted export services.
0 Kudos