I am consuming an external webservice from within my SQL Anywhere 17 using the following code:

create or replace function F1("JsonLoad" long varchar)

returns long varchar

url 'https://USER:PWD@localhost/index.php/mytest'

CERTIFICATE 'file=C:\TEMP\mycer.cer'

type 'http:post:application/json'


create or replace procedure P1("JsonLoad" long varchar)

begin

call F1(JsonLoad);

end;

The question is, how can I feed the USER & PWD from within P1?

OR

How can I change the definition of F1 so that it reads the values of USER & PWD from a table in DB

asked 10 Apr, 14:29

Sako's gravatar image

Sako
1.0k405493
accept rate: 25%

edited 10 Apr, 14:30


You can use parameter substitution

Example (note the !user and !pwd in the url clause):

create or replace function F1( 
                    "user" long varchar,
                    "pwd"  long varchar,
                    "JsonLoad" long varchar )
returns long varchar
url 'https://!user:!pwd@localhost/index.php/mytest'
CERTIFICATE 'file=C:\TEMP\mycer.cer'
type 'http:post:application/json'

create or replace procedure P1("JsonLoad" long varchar)
begin
    call F1( 'myuser', 'mypassword', JsonLoad );
end;
permanent link

answered 11 Apr, 17:08

Mark%20Culp's gravatar image

Mark Culp
24.4k9137289
accept rate: 40%

edited 13 Apr, 10:50

Just to add: Like Mark has shown above and answered here, web client functions (and also web client procedures) can be parameterized with the "!param" syntax - but the work to calculate or query values for these parameters must be done outside the web client functions.

Web client functions simply build a request from their input values, send it to the according web server, wait for the response and fetch and return it in the desired way. And that's all (although technically, that's certainly pretty much work...).

So in most cases you will need wrappers (usually "normal" functions/procedures like P1 in your sample) to calculate parameter values for the web client functions (say, by querying database contents and the like), then calling the web client function with these parameters, and then probably work on the web client function's return value to pick up the relevant information like error states, particular fields and the like. I have never used a web client function without having to wrap its call with one or more "outer" functions and produres.

permanent link

answered 13 Apr, 14:51

Volker%20Barth's gravatar image

Volker Barth
36.1k342501749
accept rate: 34%

1

@volker bath, thanks for the explanation and sorry for the duplicated question.

Regards

(13 Apr, 19:48) Sako
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×39

question asked: 10 Apr, 14:29

question was seen: 105 times

last updated: 13 Apr, 19:48