Web AppBuilder Print widget and proxy service

12701
10
Jump to solution
03-31-2016 02:48 PM
ChristopherSchreiber
Occasional Contributor II


Hello all!

I have a app that I created using Web AppBuilder (WAB) Developer Edition. We are hosting the app on our web server. The map and all the layers are hosted on ArcGIS Online (AGOL).

I have configured the Esri Proxy service that is available on GitHub in order load the app without prompting for AGOL credentials.

The app that I created has the "out of the box" print widget enabled. When the proxy is disabled, and the user must login manually when the app loads, the print widget works fine.

When the proxy is enabled for the app, the print widget does not work.

====================================================================================

Here is the error I get on Fiddler web debugger:

{"error":{"code":400,"message":"Unable to complete operation.","details":["Error executing tool. Export Web Map Task Job ID: ID12345ABCDE : Layer \"Road Detours\": Failed to create layer from service at https://our_agol_server/XtlHFoXqFDQ/arcgis/rest/services/Training_Road_Closures/FeatureServer/2.\nLa... \"Road Closures\": Failed to create layer from service at https://our_agol_server/XtlHFoXqFDQ/arcgis/rest/services/Training_Road_Closures/FeatureServer/1.\nLa... \"Road Blocks\": Failed to create layer from service at https://our_agol_server/XtlHFoXqFDQ/arcgis/rest/services/Training_Road_Closures/FeatureServer/0.\nFa... to execute (Export Web Map).\nFailed to execute (Export Web Map Task)."]}}

=====================================================================================

These three layers (Road Closures, Detours, and Blocks) are the only layers on the map that need to utilize the proxy.

It would seem that the "out of the box" proxy widget is not "proxy aware".

Is there anyone who has had a similar situation and found a solution or work around?

Thanks in advance!

Chris

1 Solution

Accepted Solutions
ChristopherSchreiber
Occasional Contributor II

Hello all, just another update for those who are still following along!

I spoke with the Print widget guys at the UC in San Diego a few weeks ago (June/July 2016). They told me that in order for the print service to work, the proxy must be changed so that it will add a token on to a JSON output from the client side app. Currently, as stated above, the proxy will see the request from the print widget go through, but it will not attach a token to it. It is not the easiest solution, but it is the way to go.

Thanks, If anyone has found a workaround to this issue, please let me know!

Chris

View solution in original post

10 Replies
ChristopherSchreiber
Occasional Contributor II

Hello all!

Just wanted to update this issue!

After working with Esri Support, we were able to come up with a solution.

The security token cookie that AGOL creates when you log in manually was not being passed from the proxy service to the app and the print widget needs to pass that token (from the cookie) to AGOL in order for it to access the layers to generate the map.

The widget did not have the token (from the cookie) to pass to the Esri Print service, therefore, the Esri Print service did not have access to our AGOL hosted layers.

The solution that Esri Support suggested was to create our own print service utilizing Server for ArcGIS. Upon testing, this seemed to work.

Thanks!

Chris

ChristopherSchreiber
Occasional Contributor II

Hello all,

Another Update:

I kept looking into this problem and I found our why the Esri proxy will not work with printing secured services.

Here is what I found:

==========================================================================================

Post by: Artemis Fili

The resource proxy will not print a secured map service. This is by design. So it is possible to use the proxy in order to authenticate and display the secured service on the map, but when it comes to printing a secured service, the resource proxy will not handle this scenario as it will not pass the token in the Web_Map_as_JSON parameter. If you are using a short lived token, then a solution would be to let the identity manager handle the authentication for you, meaning that you will get a prompt to enter your credentials once the app loads and then these credentials will be used when you try to print. Otherwise, you can create a custom print service and embed the credentials as described in the article. If you choose to use the second option, please make sure that you use a 10.3 print service or above as there was an issue in the earlier versions which is fixed in 10.3

Link:

PrintTask, Secure AGS Service, and Resource Proxy

==========================================================================================

Chris

ChristopherSchreiber
Occasional Contributor II

Hello all, just another update for those who are still following along!

I spoke with the Print widget guys at the UC in San Diego a few weeks ago (June/July 2016). They told me that in order for the print service to work, the proxy must be changed so that it will add a token on to a JSON output from the client side app. Currently, as stated above, the proxy will see the request from the print widget go through, but it will not attach a token to it. It is not the easiest solution, but it is the way to go.

Thanks, If anyone has found a workaround to this issue, please let me know!

Chris

DiegoSalcedo2
New Contributor

Hi Chris,

Thanks for posting updates on how to resolve this issue which I ran accross before but was able to solve by using the server printing service. I'm getting challenged now however when I add an ESRI premium content layer to a webmap and try to access it from the hosted app and I think this would also fix that issue.

Can you point me to the documentation on thow to add a token to a JSON output from the client side app, thanks.

0 Kudos
ChristopherSchreiber
Occasional Contributor II

Diego,

I am happy to post on any solutions that I find, thank you!

In response to your question:

Esri advised me to add the token to the JSON request once it reaches the proxy, not before.

They also informed me would be very difficult to add the token at the client side as, if you are using a proxy, the token is stored on the proxy server, not in the client side app. Because for this, the Esri print widget guys at the UC advised me to work with our development staff to add a custom modification onto the C# proxy (available on GitHub) that we are using.

Here is the link if you don't already have it: GitHub - Esri/resource-proxy: Proxy files for DotNet, Java and PHP.

I have used Esri premium content in maps before, in order to circumvent the need for the end user to authenticate, I have used Esri's Hosted Proxies​. To use them, just add the layer to your ArcGIS Online content and opt to store credentials with the premium content layer. Be advised: If you do this with any service or layer that uses credits, the credentials that you enter will be charged. I have successfully printed using the ArcGIS Online print utility tool with that layer on the map.

ArcGIS Online Print Utility: Task: Export Web Map Task

Sorry I could not be of more assistance, if I get any more updates I will pass them along.

Just as a side note, Esri advised to avoid adding custom functionality directly into the current Print widget as in the future, the print services will be revamped to allow for templates created using ArcGIS Pro.

Chris

ShaunConway
Occasional Contributor II

I am in the exact same situation. How did you add the token to the JSON request?

Thanks!

0 Kudos
ChristopherSchreiber
Occasional Contributor II

Shaun,

We were able to develop our own proxy that resides within our application. It is similar to the Esri proxy. Unfortunately, I am not able to share it at this time, but I can tell you how we made it work with the Print widget. 

NOTE: These would only work for the DotNet version of the Esri resource proxy.

  1. Get the "Web_Map_as_JSON" (WMAJ) parameter (and data it contains) from the the request. 
  2. Using a library like Newtonsoft.Json, deserialize the WMAJ data from a JSON object into a DotNet Object
  3. Get the "Operational Layers" section of the WMAJ object and add each layer into an array.
  4. Compare the Layer URL's of the layers from the WMAJ object and the URL's that are defined in the proxy.config file.
  5. If a layer's URL matches a URL from the proxy config file, use the credential info to generate a token for it.
  6. Apply the token to the layer in the array of "Operational Layers"
  7. Serialize the DotNet WMAJ object (now with tokens for the secured layers) and send the request on its way.

I include the print task URL in the app's config.json file and the proxy's proxy.config file. 

I am sorry that I am unable to provide more info at this time, I hope that this helps!

Chris

by Anonymous User
Not applicable

sch7712

So to confirm, if we're using Web App Builder 1.3 with ArcGIS Server 10.2.2 this is impossible? I want to embed the credential so users do not have to enter any credentials. I understand creating the custom print service with embedded credentials and I have done this with no problem. I was sure to set it to Sychronous etc.

However, after pointing my WAB 1.3 site at the custom print service with proper credentials, it was asking for a username/password, which is unacceptable to the client.  I had also set up a proxy for this service, which is aerial imagery, so it would load and work in the Basemaps widget. Which it does just fine. But asked for a login then timed out.  I tested embedding a token in the print service URL and this fixed it. It will print just fine on the one service in the LayerList, those layers are on "Server 2" and are not secured. However, we have the imagery layer on Machine 1, and it is a layer of imagery that is secured.  I had it Secured on Arc Server but it was asking me for credentials, I guess the proxy wasn't working. So, then I decided to try it as an unlocked service (turned off security for my print GP service).  Just sits there, and eventually WAB says Timeout Exceeded. So I guess proxy is no go but that's fine I embedded the token in the URL as I've mentioned, and it was printing the non-secured vector layers in the LayerList fine. But, the imagery turned on in the Basemaps widget still isn't showing up.

Nothing in the ArcGIS Server logs for the service. Console/network traffic, nothing. just 'undefined' error.   The print service is on the same server as the one service in the map.  (only one service, I saw the other thread)  I had a proxy to this server to login to anything on it because  So, is the only solution still, to upgrade to Server 10.3+?  Or is there a workaround possible perhaps by fiddling with the proxy?

0 Kudos
ChristopherSchreiber
Occasional Contributor II

Kevin,

In my original post, I was dealing with a web map and layers that are hosted on ArcGIS Online. The layers were secured and I was using the ArcGIS Online print utility rather than one that is hosted on out own server. That being said, I was able to get the secured hosted feature layers to print using a print service that was hosted from our ArcGIS Server. Eventually, though, it would stop working and say that it didn't have the credentials to access the layers and would not work again until we restarted the ArcGIS Server. I believe that this was a short vs. long token issue but I didn't look into that much. 

In regards to your print service, are you saying that the service itself is secured? Also, Is the link for the raster layer that is being served via "Server 1" using the proxy? If you are using the DotNet proxy it would look similar to this (www.mywebserver.com/DotNet/proxy.ashx?www.server1.com/arcgis/rest/<servicename>/mapserver)

With the issues that you are seeing, I don't think that you should need to change your version of WAB. I am not sure if this is related to any bug in 10.2 server or not. I would contact Esri Support about this before you do any upgrading. 

I apologize but other than activate, and perform some minor configurations on, the print service provided with the ArcGIS Server, I have not had too much experience working with print services on server. rscheitlin‌ or rastrauch‌ may be able to help you more than I can. 

Thank you, 

Chris

0 Kudos