Select to view content in your preferred language

How do I evaluate if a web service is running?

7876
22
05-11-2015 08:02 AM
ChrisSergent
Deactivated User

Before my code runs, I would like to evaluate if a web service is running. How would I do that in JavaScript?

Tags (2)
0 Kudos
22 Replies
ChrisSergent
Deactivated User

I just wanted to evaluate the URL. All the information should exist independent of my application running, so I wanted to check if I could see any information before consuming the service.

0 Kudos
ChrisSergent
Deactivated User

I'm currently not receiving any error messages when I paste in the URL for a stopped service. Any ideas?

0 Kudos
ChrisSergent
Deactivated User

Okay, I have my service stopped right now at: test/StreetSignTest (FeatureServer)

The URL does not provide an error by opening the page; it just shows up as blank.

0 Kudos
ChrisSmith7
Honored Contributor

I'm unsure, but could you check by pulling the first layer?

http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/0

AndyGup
Esri Regular Contributor

Yes, my recommendation is to use the layer and return json: http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/0?f=json.

If you just hit the feature service it returns a 200. Not sure why, but that's why you aren't getting an error.

ChrisSergent
Deactivated User

I think that is the right way to go. I got the following message when I tried that layer:

Error: Error handling service request : Could not find a service with the name 'test/MapServer/StreetSignTest' in the configured clusters. Service may be stopped or ArcGIS Server may not be running.

Code: 500

So, do you or Andy Gup​ know what I should write to evaluate an error of 500 in my code for that URL? I have looked up how to read JSON responses, but I can find code to evaluate this.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Chris,

  Use esriRequest.

        var requestHandle = esriRequest({
          url: "http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/0",
          content: {
            f: 'json'
          },
          handleAs: "json"
        });

        requestHandle.then(function(lyrJSON, io){
          console.info(lyrJSON);
        }
ChrisSergent
Deactivated User

This one I could not get to work. It just errored out if a web service was not running but did not write to the console log.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Chris,

  OK, I forgot you were looking for the error.

Try this:

      requestHandle.then(
        function(lyrJSON, io){  
          console.info(lyrJSON);  
        }, function(err){
          console.info(err);
        }
      );
ChrisSergent
Deactivated User

I might have modified it incorrectly; here is what I updated and still get an error with a stopped web service:

var requestHandle = esriRequest({ 
        url: "http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/0", 
        content: { 
            f: 'json' 
        }, 
        handleAs: "json" 
    }); 

    requestHandle.then(
        function (lyrJSON, io) {
            console.info(lyrJSON);
        }, function (err) {
            console.info(err);
        }
      );
0 Kudos