urlUtils.addProxyRule({ urlPrefix: "http://server_for_gis/arcgis/rest/services/Secure", proxyUrl: "http://server_for_web/apps/gis/Proxy/proxy.ashx" });
esriConfig.defaults.io.proxyUrl = "http://server_for_web/apps/gis/Proxy/proxy.ashx";
"operationalLayers": [ { "id" : "mytheme", "opacity": 1, "visibility": true, "url": "http://server_for_gis/arcgis/rest/services/Secure/mytheme/MapServer" }]
http://server_for_web/apps/gis/Proxy/proxy.ashx?http://server_for_gis/arcgis/rest/services/Secure/ExportWebMapSecure/GPServer/Export%20Web%20Map?f=json status: 500"
urlUtils.addProxyRule({ urlPrefix: "http://server_for_gis/arcgis/rest/services/Secure", proxyUrl: "http://server_for_web/apps/gis/Proxy/proxy.ashx" });
Hi Dorothy....long time no talk. As you mentioned, there are many with questions re: printing secure services with Javascript. I was able to solve this issue a while back if my html was on the same server/website and I had my proxy set up. My issue came about because an html will now located on a "remove" webserver. It took some head scratching and a bit of time with a tech support analyst, but I finally got mine to work. I may try to type this up as a blog entry, but for now, I wanted to get this out there for others to try. If it works for you, please mark as solved...if not and it's all on one server, email me direct (same old email) and we can talk. Hopefully with all my buzz words in my response, others can find it. My guess is the solution will work for both JS and Flex (with the appropriate proxy). My response:
A Fix for printing secure services from remote machine. This solves errors such as
My simple understanding and explanation of the solution: Basically I needed to reference a proxy in the two locations (IIS servers). The secured services need to have the proxy (as an iis app) on the IIS server with the ArcGIS Server web adapters (i.e., within my AGS site); The print service on the other hand needs to have the proxy (as an iis app) on the iis server where the web site is hosted. The JS/HTML file needs to reference them both in their own way.
My setup:
That is, when attempting to print a map that contains secure services from a remote web server, using the ArcGIS Server "Export Web Map Task" service (default or custom), if you get an error re: CORS or "No 'Access-Control-Allow-Origin' header is present", try the following:
(This assumes: that you already have a proxy setup and working to access your secure services. In my case, it is located in the IIS site where my web adapters are located.)
NOTE: Remote machine refers to the website IIS server
require ( [….,
“esri/urlUtils”,
…],
function (… ,
urlUtils,
… ) {
These are case sensitive. Make sure to include the comma where needed and to match the order of the entry between the require and function sections. I can elaborate on the other require/function I have in my code if needed.
Then add (I add it after parser.parse(); )
urlUtils.addProxyRule({
urlPrefix: "https://<youGISiisServer>/<yourWebAdaptor>"",
proxyUrl: "https://<youGISiisServer>/<yourProxyFolderOnThatMachine>/proxy.ashx"});
// Proxy and CORS options for printing secure services from remote machines
esriConfig.defaults.io.proxyUrl = "http://<remoteIISMachine>/printProxy/proxy.ashx";
esriConfig.defaults.io.alwaysUseProxy = false;
esriConfig.defaults.io.corsDetection = false;
Make sure to change the references to your own machines and web adaptor. In the sample above, the urlUtils.addProxyRule points to the proxy on you ArcGIS Server IIS machine. The esriConfig.defaults.io.proxyUrl points to the print proxy on your non-ArcGIS Server (i.e. remote) web site.
I hope this helps you and/or others. Let me know if somethings doesn't make sense. It would be nice to make the steps a bit easier to read.
The NIM does mention it is fixed in 10.3, but there are a few other issues that will still be encountered if you want to print to a secure service. I'm using an older version of the proxy and there is a small issue there as well (not sure if fixed in latest .NET proxy) although a small change there, and/or change the timeout settings for the service to be less than token time if custom print.
Here is a summary of a few workarounds: Printing with ArcGIS for Server 10.3 - Spatial Times
This is my solution for working on ArcGIS Enterprise portal when dealing directly with JSON.
I had a published a geoprocessing service coded in python that directly access the generateToken service to create a short-term token for the particular secure service layer.
generateToken
https://<portal domain>/portal/sharing/rest/generateToken
The parameter for the generateToken service looks like this
params = {
'username': <username>,
'password': <password>,
'client': 'referer',
'referer': <secure service layer URL>,
'expiration': 1
}
When you execute a http request, you should get back a token. You need to do this for every secure service layer that you want to include into your operationalLayer
Then, in your operationLayer section, for each layer definition object, add parameter
token: <generateToken>
One thing to keep in mind is that there is a character limit on how long you can make you Web_Map_as_JSON.
So I don't imagine you can add a lot of layer with this method due to the long token string.