Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

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 '20, 14:29

Baron's gravatar image

Baron
2.1k137150177
accept rate: 48%

edited 10 Apr '20, 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 '20, 17:08

Mark%20Culp's gravatar image

Mark Culp
24.9k10141297
accept rate: 41%

edited 13 Apr '20, 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 '20, 14:51

Volker%20Barth's gravatar image

Volker Barth
40.2k361550822
accept rate: 34%

1

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

Regards

(13 Apr '20, 19:48) Baron
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:

×48

question asked: 10 Apr '20, 14:29

question was seen: 890 times

last updated: 13 Apr '20, 19:48