Link to home
Start Free TrialLog in
Avatar of lp84
lp84

asked on

How to create a SOAP request with JavaScript for Acrobat Pro 9

Hi all,

I've created a soap request using the soap.connect method - but what I really need is a way to create a soap request with the soap.request method. I need to pass authentication, and this seems to be the only way to pass in the oAuthenticate object.

Does anyone know how I can create the code for this - using a weather wsdl as an example here is my connect code:

      var strURL = "http://www.webservicex.net/globalweather.asmx?wsdl";
      var service = SOAP.connect(strURL);
      var sCountryName = "United States";
      var sCityName = "New York";
      var result = {
                  soapType: "xsd:string",
                 CountryName: sCountryName,
                   CityName: sCityName
                   //soapValue:
                  };
      var results = service.GetWeather(result);
      app.alert(results);

This works fine - however I want to do something like this for the soap.request

var myURL = "http://www.webservicex.net/globalweather.asmx?wsdl";
var echoStringRequest = {
"http://www.webservicex.net/globalweather.asmx/GetWeather" {
CityName: "New York"
CountryName: "United States"

}
};

var mySOAPAction = "http://www.webservicex.net/globalweather.asmx";


var response = SOAP.request ({
cURL: myURL,
oRequest: echoStringRequest,
cAction: mySOAPAction
});


var responseString = "http://www.example.com/methods:echoStringResponse";
var result = response[responseString]["return"];

console.println("Result is " + result);

However, i'm getting this error:

missing : after property id
3:Console:Exec
undefined

I dont think my code is right - and there is not much resources out there. Can anyone help please? Or if anyone knows how to write an async version?

Avatar of leakim971
leakim971
Flag of Guadeloupe image

After CityName: "New York"

you miss somes commas no ?
Replace :
var myURL = "http://www.webservicex.net/globalweather.asmx?wsdl";
var echoStringRequest = {
"http://www.webservicex.net/globalweather.asmx/GetWeather" { // <----- here
CityName: "New York" // <----- here
CountryName: "United States"

}
};

By :
var myURL = "http://www.webservicex.net/globalweather.asmx?wsdl";
var echoStringRequest = { "http://www.webservicex.net/globalweather.asmx/GetWeather", { CityName: "New York", CountryName: "United States" } };

Open in new window

Check this page too :


http://www.verydoc.com/documents/acrojsguide/pg_0254.htm

Open in new window

Avatar of lp84
lp84

ASKER

still having the same error. Do you know how I can setup the syntax? - that page is a bit confusing, in terms of syntax. Just need some proper working examples to follow. thanks a lot though.
What about :


var myURL = "http://www.webservicex.net/globalweather.asmx?wsdl";
var echoStringRequest = { cURL:"http://www.webservicex.net/globalweather.asmx/GetWeather", oRequest:{ CityName: "New York", CountryName: "United States" } };

Open in new window

>that page is a bit confusing, in terms of syntax. Just need some proper working examples to follow. thanks a lot though.
page 664 here : http://www.adobe.com/devnet/acrobat/pdfs/js_api_reference.pdf
the example with SOAP.request start at page 670
Avatar of lp84

ASKER

SOAPError: System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: http://www.webservicex.net/globalweather.asmx.
   at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
   at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
   at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
   at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)
   at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
SOAP.request:13:Console undefined:Exec

undefined

Bit closer...

I actually am on that PDF - that is what i used to follow
Avatar of lp84

ASKER

Still trying a simple synchronous request and I cant see mto get past the http header error
Do you just want to know how to make an aync SOAP call?
You get the last error after following example on page 664 ?
Avatar of lp84

ASKER

well I was trying to do the synchronous way thinking it would be easier - but I cannot even do that. If you can show me how to do the async one that will be very appreciated.

No I wasn't sure how to setup the header..tried a few times but kept getting undefined errors
The following :


var cURL = "http://www.webservicex.net/globalweather.asmx";
var oRequest = {"http://www.webserviceX.NET:GetWeather":{CityName:"New York",CountryName:"United States"}};
var cAction = "http://www.webserviceX.NET/GetWeather";
var ver = SOAPVersion.version_1_2;
SOAP.wireDump = "true";
var response = Net.SOAP.request({cURL:cURL,oRequest:oRequest,cAction:cAction,bEncoded:false,cVersion:ver});

Open in new window

produce :


<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<SOAP-ENV:Body>
		<ns0:GetWeather xmlns:ns0="http://www.webserviceX.NET">
			<CityName>New York</CityName>
			<CountryName>United States</CountryName>
		</ns0:GetWeather>
	</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Open in new window

A good one :


<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<SOAP-ENV:Body>
		<ns0:GetWeather xmlns:ns0="http://www.webserviceX.NET">
			<ns0:CityName>New York</ns0:CityName>
			<ns0:CountryName>United States</ns0:CountryName>
		</ns0:GetWeather>
	</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Open in new window

The following "run" fine because the parameter "name" is optional :


//
var cURL = "http://www.guru4.net/articoli/javascript-soap-client/demo/webservicedemo.asmx";
var oRequest = {"http://www.guru4.net:HelloTo":{name:"leakim971"}};
var cAction = "http://www.guru4.net/HelloTo";
var cVersion = SOAPVersion.version_1_2;
SOAP.wireDump = "true";
var response = Net.SOAP.request({cURL:cURL,oRequest:oRequest,cAction:cAction,bEncoded:false,cVersion:cVersion});
app.alert(response);

Open in new window

The response is not the good :

(return "Hello !" and not "Hello leakim971!")
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<soap:Body>
		<HelloToResponse xmlns="http://www.guru4.net/">
			<HelloToResult>Hello !</HelloToResult>
		</HelloToResponse>
	</soap:Body>
</soap:Envelope>

Open in new window

Avatar of lp84

ASKER

Thanks Leakim! They both work well!

One last question. I went thru the java doc for acrobat and used the oAuthenticate object to add in the authentication header, did it for both examples:

var oAuthenticator ={ Username: "test", Password: "test"};
var cURL = "http://www.webservicex.net/globalweather.asmx";
var oRequest = {"http://www.webserviceX.NET:GetWeather":{CityName:"New York",CountryName:"United States"}};
var cAction = "http://www.webserviceX.NET/GetWeather";
var ver = SOAPVersion.version_1_2;
SOAP.wireDump = "true";
var response = Net.SOAP.request({cURL:cURL,oRequest:oRequest,cAction:cAction,oAuthenticate:oAuthenticator,bEncoded:false,cVersion:ver});

var oAuthenticator ={ Username: "test", Password: "test"};
var cURL = "http://www.guru4.net/articoli/javascript-soap-client/demo/webservicedemo.asmx";
var oRequest = {"http://www.guru4.net:HelloTo":{name:"leakim971"}};
var cAction = "http://www.guru4.net/HelloTo";
var cVersion = SOAPVersion.version_1_2;
SOAP.wireDump = "true";
var response = Net.SOAP.request({cURL:cURL,oRequest:oRequest,cAction:cAction,oAuthenticate:oAuthenticator,bEncoded:false,cVersion:cVersion});
app.alert(response);

I am wondering if that will work for NTLM?
page 550 set UsePlatformAuth to true
So you don't need  Username and Password are ignored.

Avatar of lp84

ASKER

Awesome!! Like this? I ran it, seems to work



var oAuthenticator ={ UsePlatformAuth: "true"};
var cURL = "http://www.webservicex.net/globalweather.asmx";
var oRequest = {"http://www.webserviceX.NET:GetWeather":{CityName:"New York",CountryName:"United States"}};
var cAction = "http://www.webserviceX.NET/GetWeather";
var ver = SOAPVersion.version_1_2;
SOAP.wireDump = "true";
var response = Net.SOAP.request({cURL:cURL,oRequest:oRequest,cAction:cAction,oAuthenticate:oAuthenticator,bEncoded:false,cVersion:ver});

var oAuthenticator ={ UsePlatformAuth: "true"};
var cURL = "http://www.guru4.net/articoli/javascript-soap-client/demo/webservicedemo.asmx";
var oRequest = {"http://www.guru4.net:HelloTo":{name:"leakim971"}};
var cAction = "http://www.guru4.net/HelloTo";
var cVersion = SOAPVersion.version_1_2;
SOAP.wireDump = "true";
var response = Net.SOAP.request({cURL:cURL,oRequest:oRequest,cAction:cAction,oAuthenticate:oAuthenticator,bEncoded:false,cVersion:cVersion});
app.alert(response);
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lp84

ASKER

Ah..thanks a lot for all your help!