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?
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]["
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?
Check this page too :
http://www.verydoc.com/documents/acrojsguide/pg_0254.htm
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" } };
>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
page 664 here : http://www.adobe.com/devnet/acrobat/pdfs/js_api_reference.pdf
the example with SOAP.request start at page 670
ASKER
SOAPError: System.Web.Services.Protoc ols.SoapEx ception: Server did not recognize the value of HTTP Header SOAPAction: http://www.webservicex.net/globalweather.asmx.
at System.Web.Services.Protoc ols.Soap11 ServerProt ocolHelper .RouteRequ est()
at System.Web.Services.Protoc ols.SoapSe rverProtoc ol.RouteRe quest(Soap ServerMess age message)
at System.Web.Services.Protoc ols.SoapSe rverProtoc ol.Initial ize()
at System.Web.Services.Protoc ols.Server Protocol.S etContext( Type type, HttpContext context, HttpRequest request, HttpResponse response)
at System.Web.Services.Protoc ols.Server ProtocolFa ctory.Crea te(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
at System.Web.Services.Protoc
at System.Web.Services.Protoc
at System.Web.Services.Protoc
at System.Web.Services.Protoc
at System.Web.Services.Protoc
SOAP.request:13:Console undefined:Exec
undefined
Bit closer...
I actually am on that PDF - that is what i used to follow
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 ?
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
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});
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>
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>
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);
The response is not the good :
(return "Hello !" and not "Hello leakim971!")
(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>
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:cUR L,oRequest :oRequest, cAction:cA ction,oAut henticate: oAuthentic ator,bEnco ded:false, cVersion:v er});
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:cUR L,oRequest :oRequest, cAction:cA ction,oAut henticate: oAuthentic ator,bEnco ded:false, cVersion:c Version});
app.alert(response);
I am wondering if that will work for NTLM?
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:cUR
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:cUR
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.
So you don't need Username and Password are ignored.
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:cUR L,oRequest :oRequest, cAction:cA ction,oAut henticate: oAuthentic ator,bEnco ded:false, cVersion:v er});
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:cUR L,oRequest :oRequest, cAction:cA ction,oAut henticate: oAuthentic ator,bEnco ded:false, cVersion:c Version});
app.alert(response);
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:cUR
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:cUR
app.alert(response);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ah..thanks a lot for all your help!
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 :
Open in new window