Printing secured services...

788
1
Jump to solution
10-09-2018 03:02 AM
UjjwalNigam
New Contributor III

Hi,

ArcGIS Server Version: 10.4.0

ArcGIS JS API: 3.25

ArcGIS Desktop: 10.2.1

Browser: IE 11

In my web application, I am consuming secured services and have a requirement to print the map contents.

Initially, the token expiry was set to default (i.e. 60 mins) and everything worked fine including printing, using the Utilities/PrintingTools GP Service.

As part of the requirement, the token expiry was increased from 60 mins to 240 mins - everything still worked fine except for printing! Looking up the esri help it was clear I had to create a custom service. I created the custom service as described in the help documents, but it still fails with the following error:

Error executing tool. Export Web Map Task Job ID: jb88972125ace4b6593c8055ee779e920 : Layer "dynLyrId": Unable to connect to map server at https://server.domain:6443/arcgis/rest/services/WebViewer/MapServer/. Failed to execute (Export Web Map). Failed to execute (Export Web Map Task).

The custom service has a user connection (with saved credentials) embedded into it as required.

Upon investigating further, I found out that if I remove the token from the WebMapAsJson, it works like a charm (in ArcCatalog at least)!

I don't know how to do that as I am not creating the WebMapAsJson manually, but the esri JS API creates it while sending the request. I also tried to increase the ArcGIS Servers' shortTimeout value from 60 to 240 but even that failed.

Any ideas to make the printing work with long-validity tokens?

Regards

Ujjwal

0 Kudos
1 Solution

Accepted Solutions
UjjwalNigam
New Contributor III

So, removing the token from the WebMapAsJSON string and calling the execute URL using standard XHR did the trick! Attaching the code here for reference.

Notice the use of undocumented function PrintTaskObject._getPrintDefinition(map, printParams).

var Web_Map_as_JSON = printTaskObj._getPrintDefinition(map, printParams);
    delete Web_Map_as_JSON.operationalLayers[0].token;

    //add export options
    var expOptions = ', "exportOptions":{"outputSize":[' + pageWidth + ',' + pageHeight + '],"dpi":' + pageDpi + '}';
    var strWebMapJson = JSON.stringify(Web_Map_as_JSON);
    Web_Map_as_JSON = strWebMapJson.slice(0, strWebMapJson.lastIndexOf('}')) + expOptions + '}';

    var payLoad = {
        "Web_Map_as_JSON": Web_Map_as_JSON,
        "Format": "PNG32",
        "Layout_Template": "MAP_ONLY",
        "f": "json"
    };

    //call execute endpoint via XHR
    $.ajax({
        type: "POST",
        url: printGPTaskUrl + "?token=" + token,
        data: payLoad,
        success: printSuccess
    });

View solution in original post

0 Kudos
1 Reply
UjjwalNigam
New Contributor III

So, removing the token from the WebMapAsJSON string and calling the execute URL using standard XHR did the trick! Attaching the code here for reference.

Notice the use of undocumented function PrintTaskObject._getPrintDefinition(map, printParams).

var Web_Map_as_JSON = printTaskObj._getPrintDefinition(map, printParams);
    delete Web_Map_as_JSON.operationalLayers[0].token;

    //add export options
    var expOptions = ', "exportOptions":{"outputSize":[' + pageWidth + ',' + pageHeight + '],"dpi":' + pageDpi + '}';
    var strWebMapJson = JSON.stringify(Web_Map_as_JSON);
    Web_Map_as_JSON = strWebMapJson.slice(0, strWebMapJson.lastIndexOf('}')) + expOptions + '}';

    var payLoad = {
        "Web_Map_as_JSON": Web_Map_as_JSON,
        "Format": "PNG32",
        "Layout_Template": "MAP_ONLY",
        "f": "json"
    };

    //call execute endpoint via XHR
    $.ajax({
        type: "POST",
        url: printGPTaskUrl + "?token=" + token,
        data: payLoad,
        success: printSuccess
    });
0 Kudos