Calling asmx web service from javascript

3798
5
11-23-2016 03:53 AM
wadsonmakari
New Contributor III

Dear all,

I have some legacy asmx web services that I would like to call from javascript for the custom widget I am building. The asmx web service has a number of operations that take input parameters to run. I have attempted to the web service as shown below

var requestData = esriRequest({

   url: ".../webservice.asmx/OperationName",

   content: {parameterName: "parameterVale"},

   handleAs: "xml"

});

requestData.then(

   function (data){

      console.log("Data:",data);

},

function (error){

   console.log("error:",error);

}

When I run I get the following error in the console

RequestError: Unable to load //mydomainname/webservicename.asmx/OperationName?parameterName=parameterValue status: 500.

I can run the webservice manually by the way and it returns the result xml as I expect to. Any ideas will be much appreciated.

Using Javascript 3.18

0 Kudos
5 Replies
LoriGonzalez
New Contributor III

I've had a similar issue.  For the 'content' attribute of esriRequest make sure you are passing the same number of parameters your asmx service expecting even if their values are empty.    

var requestData = esriRequest({

   url: ".../webservice.asmx/OperationName",

   content: {
"FirstName": "",
"LastName": "",
"StartDate": "1/1/2000"
},

   handleAs: "xml"

});

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Wadson,

   Is your asmx SOAP or REST? I have never had any luck using a SOAP based web service, but I have many apps using RESTful web services.

0 Kudos
JoseSanchez
Occasional Contributor III

Hello everyone,

I am writing my first esriRequest, what do I need to add in the   "content: {" section if I am calling the default  "HelloWorld" method?    I am trying to call a asmx web service

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jose,

  I don't believe that the hello world method take s any parameters so you don't use the content portion.

0 Kudos
BillChappell
Occasional Contributor II

Might be a simple CORS issue. I've run into this when I manually check a service and it runs then try to hit it with code and it doesn't. Check the console.

0 Kudos