CreateAGSServerConnection

摘要

用于创建可用于访问 ArcGIS Server 站点的 ArcGIS Server 连接文件。

说明

当您创建 ArcGIS Server 连接并且 ArcGIS Server 站点已与 ArcGIS Enterprise 部署联合时,必须使用 ArcGIS Enterprise 门户登录。 可使用 SignInToPortal 函数执行此操作。 对于这些站点,您只能创建使用站点内容的连接。

当您创建 ArcGIS Server 连接且 ArcGIS Server 站点是独立部署时,默认情况下将创建用户级连接。 您可以请求将连接文件的连接升级,以支持发布服务。 仅当已连接的用户具有足够的权限来允许升级连接时,才会接受此请求。

系统提供不同的选项来控制 ArcGIS Server 站点内容的访问权限。 如果已将站点配置为使用内置身份存储且不允许匿名访问,则需要用户名和密码。 创建连接文件的用户必须考虑其预期用途,以正确考虑存储凭据和使用文件的方式,如下所示:

  • 默认情况下,新连接文件中不会永久存储任何凭据,因为这是最安全的选项。 如果未保存凭据,则使用该文件的脚本必须管理 ArcGIS Server 站点的登录,以避免在脚本运行时出现登录对话框。 脚本可以使用 ImportCredentials 函数从另一个 ArcGIS Server 连接文件导入凭据。
  • 如果文件将由支持自动发布操作的脚本使用,则将凭据存储在连接文件中很有用,但必须注意保持脚本和文件的安全,因为发布操作需要高级权限。 发布不同的服务可能需要不同的高级凭据。
  • 如果该文件将用于访问服务并将其添加到地图,则必须了解制图系统将首先利用已建立的 ArcGIS Server 站点连接。 如果内存中没有可用的连接,则制图系统仅利用存储在用户个人资料中的 Windows 凭据管理器中的凭据来建立新连接。 如果 Windows 凭据管理器中的凭据不可用,则打开地图的用户必须登录。

使用适当的权限创建 ArcGIS Server 连接文件后,您可以使用 UploadServiceDefinition 函数上传服务定义文件。

语法

CreateAGSServerConnection (ags_file_path, server_url, {username}, {password}, {save_credentials_to_wcm}, {save_credentials_to_file}, connection_type)
参数说明数据类型
ags_file_path

The folder path where the output ArcGIS Server connection file (.ags) will be stored and the name of the file that will be created. The file extension must be .ags.

String
server_url

The URL of the ArcGIS Server site. You mustspecify the server URL according to the site requirements. ArcGIS Pro only supports HTTPS connections to ArcGIS Server deployments.

String
username

The username that will be used forArcGIS Server authentication if the ArcGIS Server site is a stand-alone deployment and has been configured to use a built-in identity store; a username is required in this configuration if anonymous access is not allowed.

In all other configurations, provided credentials are ignored and will not be saved. When the ArcGIS Server site is federated with an ArcGIS Enterprise deployment, you must sign in using the ArcGIS Enterprise portal.

String
password

The password that will be used forArcGIS Server authentication if the ArcGIS Server site is a stand-alone deployment and has been configured to use a built-in identity store; a password is required in this configuration if anonymous access is not allowed.

In all other configurations, credentials are ignored and will not be saved. When the ArcGIS Server site is federated with an ArcGIS Enterprise deployment, you must sign in using the ArcGIS Enterprise portal.

String
save_credentials_to_wcm

Specifies whether the username and password forArcGIS Server authentication will be stored in the Windows Credential Manager, which is part of the computer's operating system.

The ArcGIS Pro mapping system only uses credentials stored in the Windows Credential Manager to sign in to the ArcGIS Server site, access its content, and draw data, because this storage mechanism is secure. If an operation is performed or a script is run on a different machine using the same connection file, the required credentials may not be available because a sign in has not yet occurred on that computer. A sign-in dialog box may appear.

  • True—The username and password will be saved in the Windows Credential Manager.
  • False—The username and password will not be saved in the Windows Credential Manager.

(默认值为 False)

Boolean
save_credentials_to_file

Specifies whether the username and password forArcGIS Server authentication will be stored in the ArcGIS Server connection file (.ags).

Python scripts can use the SignInToPortal function to access a federated server's content. For a stand-aloneArcGIS Server site, a script run on a Linux machine will not have access to the Windows Credential Manager to sign in and access the site's content. Use an encrypted login in your script; this option is more secure. Credentials can also be stored in the connection file; this option is less secure.

  • True—The username and password will be saved in the server connection file.
  • False—The username and password will not be saved in the server connection file.

(默认值为 False)

Boolean
connection_type

Specifies the connection type that will be created to use or publish content on an ArcGIS Server site.

When the ArcGIS Server site is federated with an ArcGIS Enterprise deployment, you can only create a connection to use the site's content. When the ArcGIS Server site is a stand-alone deployment, and you have sufficient privileges, the connection is created with the requested elevated connection type.

  • USE_SERVICES—Map and feature services are listed along with other items accessible with your credentials. This is the only option if you connect to a federated server.
  • PUBLISH_SERVICES—You can publish services, except geoprocessing services, to a stand-alone ArcGIS Server site. Items accessible with your credentials are listed; however, feature services are not included in the list.
  • ADMINISTER_SERVICES—You can publish all services to a stand-alone ArcGIS Server site. Items available with your credentials are listed; however, feature services are not included in the list.

(默认值为 USE_ SERVICES)

String
返回值
数据类型说明
String

ArcGIS Server 连接文件的完整路径。

代码示例

CreateAGSServerConnection 示例 1

创建 ArcGIS Server 连接文件以从任何 ArcGIS Server 站点匿名访问服务。 站点可以与 ArcGIS Enterprise 门户联合,也可以是独立部署。

import arcpy
agsFileName = arcpy.CreateAGSServerConnection(
    r"C:\Project\MyOrganization.ags",
    "https://organization.example.com/server")
CreateAGSServerConnection 示例 2

创建可用于将服务发布到独立 ArcGIS Server 部署的 ArcGIS Server 连接文件。

import arcpy
12345678901234567890123456789012345678901234567890123456789012345678901234567890
agsFileName = arcpy.CreateAGSServerConnection(
    r"C:\Project\MyServer.ags",
    "https://organization.example.com/arcgis",
    "MyUserName",
    "MyPassword",
    False,
    True,
    "PUBLISH_SERVICES")