cancel
Showing results for 
Search instead for 
Did you mean: 

Webservice Call from another DB

Baron
Participant
1,462

Hi, I have 2 SQL-Anywhere DBs, each of them has several Webservices. Is there a way to call the the Webservice on DB1 from within DB2?

Now I can imagine that I can use CURL for this purpose, and then output the Service response in a text file, and then read the response from this text file.

Is there maybe a ready function in Sybase 10?

Thanks in advance

Accepted Solutions (1)

Accepted Solutions (1)

VolkerBarth
Contributor

Of course you can, even with v10, and no need to fiddle with calling external tools. See the following doc topic:

Creating web service client functions and procedures

This forum certainly has a bunch of questions dealing with web client functions/procedures.

Baron
Participant
0 Kudos

Thank you very much. Very useful is that the parameters list which are defined in:

CREATE PROCEDURE [ owner.]procedure-name ( [ parameter, ... ] )

Will be the parameters of the URL ('?' '=' '&' will be automatically added)

Baron
Participant
0 Kudos

One more question please.

If I apply the example in the link sent:

CREATE PROCEDURE MyOperation ( a INTEGER, b CHAR(128) )

URL 'HTTP://localhost'

TYPE 'SOAP:DOC';

++++++++++++

CALL MyOperation( 123, 'abc' )

How can I read the output of MyOperation (I need to get the Response of HTTP://localhost).

in other words, I need something like select * from MyOperation( 123, 'abc' ) Here I get error message (MyOperation does not return result set).

Even with the following block I can not solve the problem!

CREATE function MyOperation ( a INTEGER, b CHAR(128) )

returns varchar

URL 'HTTP://localhost'

TYPE 'SOAP:DOC';

+++++++++++++++

select * from MyOperation( 123, 'abc' )

VolkerBarth
Contributor
0 Kudos

Hm, v11.0.0 has introduced a facility to log web client requests and responses via the -zoc server option and/or sa_server_option settings. I found that very helpful in developping web client procedures.

Nevertheless, the docs certainly do tell the difference between using web client functions vs. procedures based on their different result (sets). When using functions, you get a XML that can be extracted via openxml.

Baron
Participant
0 Kudos

Thanks for the reply, I still have difficulty with OPENXML. The response of my webservice looks like:

<root>

<row updresult="OK"/>

</root>

How can I read the "OK"?

I tried the following without success:

select * from openxml (get_webservices(), '/row') with ("ResultfromSRV" char(5) '@UpdResult')

VolkerBarth
Contributor
0 Kudos

This is more an OpenXML question. I'd recommend to ask that as a separate question.

VolkerBarth
Contributor

FWIW, here's a sample:

select *
from openxml(
   '<root>
    <row updresult="OK"/>
    </root>',
   '//row')
with (LocalName long varchar '@mp:localname', LocalText long varchar '@mp:xmltext', ResultfromSRV varchar(5) '@updresult')

returns

LocalName,LocalText,ResultfromSRV

row,<row updresult="OK"/>,OK

I suggest to use those meta properties like @mp:xmltext and the like to check whether you are "looking at the rigt nodes" , in your sample the XPath was not fitting as it missed the initial slash, therefore the '//row'.

Baron
Participant
0 Kudos

Thank you very much. I am missing gneral knowledge in XML

Answers (1)

Answers (1)

Breck_Carter
Participant

In additiion to what Volker said, if you get 403 Forbidden when trying to call a service from a client on the same database, try HEADER 'ASA-Id'.

I'm not sure that also applies to different databases on the same SQL Anywhere server, but it might.

Here's a snippet from my Vast Template Collection :)...

CREATE PROCEDURE c ( 
   urlspec    LONG VARCHAR )
RESULT (
   attribute   LONG VARCHAR,
   value       LONG VARCHAR )
URL '!urlspec'
HEADER 'ASA-Id'   -- avoid same-server error "HTTP request failed. Status code '403 Forbidden'"
TYPE 'HTTP:GET';