How do I publish a service using a service definition file (.sd) through the ArcGIS Server REST API?

666
6
Jump to solution
10-04-2019 10:10 AM
ChristopherVirtucio
New Contributor II

Hi,

I asked a question on gis.stackexchange.com on how I should be publishing a service through the REST API. I'm reproducing the question here for convenience:

The algorithm I have so far is basically this:

  1. Create a sddraft from a mxd file (using arcpy.CreateMapSDDraft().
  2. Stage sddraft into a sd file (using arcpy.StageService_server().
  3. Upload sd file to ArcGIS server over REST.
    1. There's a little dance that has to happen due to the fact that we use web-adaptor and have to redirect all requests to a single-sign-on server first for authentication, before forwarding the intended request to the intended destination.
  4. Call createService on ArcGIS server's REST API, pointing to the uploaded sd file.
    1. This happens in the same http session, so no need to go through the authentication dance again.

The fourth step manages to create the service, but startup fails due to Invalid file. The only documentation for the createService endpoint that I could find is this, and I can only surmise that the endpoint only accepts the old and deprecated msd file, but not the newer sd file. If that's the case, what endpoint am I supposed to hit for creating a service from a sd file? Note that arcpy.UploadServiceDefinition() isn't an option for us due to the fact that authentication is handled elsewhere from the ArcGIS server.

I was wondering if anyone would happen to know the answer for this.

Thanks,

CJ

1 Solution

Accepted Solutions
ChristopherVirtucio
New Contributor II

Figured it out; solution available here.

View solution in original post

Reply
0 Kudos
6 Replies
JonathanQuinn
Esri Frequent Contributor

The SD file packages the necessary files and folders for the service. It can't be used directly against the createService API. The createService API requires service JSON, which requires a bit of pre-work to create the necessary folders and other metedata. Instead, if you upload the service through Manager, watch the network traffic and re-create the requests in your language of choice. At a high level, its:

1) Upload to the Admin API

2) Get the service configuration

3) Run Publish Service Definition with the service configuration

4) Check the job status until a success or failure.

Reply
0 Kudos
ChristopherVirtucio
New Contributor II
1) Upload to the Admin API

Could you clarify? Which method of arcpy would that be?

2) Get the service configuration

3) Run Publish Service Definition with the service configuration

Doesn't this require an arcpy connection object? How do we create one when we use an external authentication service?

Reply
0 Kudos
JonathanQuinn
Esri Frequent Contributor

The workflow I described won't use any arcpy functions, aside from creating the SDDraft and the SD file.You'd be using straight Python to upload files (an SD file) to a website, (the Admin API), and then publish it using the Publishing Tools GP service. Run through the process manually through ArcGIS Server Manager and watch the network traffic. You'll be re-creating all of those requests within Python. What authentication service are you using? As long as there are libraries to handle the authentication, (requests, requests_ntlm, etc), you shouldn't have a problem.

Reply
0 Kudos
ChristopherVirtucio
New Contributor II

Ok, I got a little confused since I wasn't sure if you were referring to REST calls or the arcpy library.

I actually did manage to write something that's close to what I think you're referring to. We use CAS , and I'm already doing the authentication bit per the question I linked above. I upload the file, then call createService, which manages to create the service, but startup fails. Your comment did point out something that I admittedly should have been doing, though, which is to see what the actual requests are, so I can mimic those.

Reply
0 Kudos
ChristopherVirtucio
New Contributor II

Managed to inspect the different steps of the manually publishing process. There's a POST request for a job at the path:

/rest/services/System/PublishingTools/GPServer/Publish%20Service%20Definition

The API seems to take the ff. params:

1. in_sdp_id

2. in_config_overwrite

3. in_publish_options

4. out_soap_svc_url

5. out_rest_svc_url

6. out_results

But it's not very clear what each of the params mean, nor is it clear how I'm supposed to generate them.

edit: seems like in_sdp_id refers to the identifier of the file that the server gives you after uploading it

Reply
0 Kudos
ChristopherVirtucio
New Contributor II

Figured it out; solution available here.

View solution in original post

Reply
0 Kudos