cancel
Showing results for 
Search instead for 
Did you mean: 

Anyone knows how to call a web service within UDF(UserDefinedFunction)?

Former Member
0 Kudos

Does anyone knows how to <b>call a web service within UDF</b>(UserDefinedFunction)? Esp., how to structure the SOAP msg in DOM?

I am using <b>XI-Sp15</b>, and tried hard with my friends, but no success (Always got Fault response)! We used JCO to directly call a RFC, it works fine, but we still want to know if it is possible to call a web service within UDF, <b>through XI SOAP adapter</b>?!

Any advise is welcome and appreciate...

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

You can use the Lookup API for that purpose. Please refer to the SAP Online Help and the Weblogs posted about this topic already. By using this, you can either call an RFC, a Web Service (via SOAP Channel) or a JDBC (via JDBC Channel) as part of your user defined function. If you check the Weblogs, you will find some examples for the usage.

(e.g. /people/morten.wittrock/blog/2006/03/30/wrapping-your-mapping-lookup-api-code-in-easy-to-use-java-classes)

regards,

Peter

Answers (1)

Answers (1)

Former Member
0 Kudos

Thanks, peter,

Actually, we used the SAP mapping lookup API tried <b>DB lookup, RFC lookup</b>, all have <b>no problem</b>. But just <b>can not make a web service call by using those mapping API</b>. Please see the following code(I did not put all code here for saving posting space. I have read your webblog, I am positive that it is easy for you to understand these pieces of code...I just guess the error probally happens on the XMLpayload, but see no any example about this. <b>All examples on net are all about RFC/DB lookup, no web service lookup, IN UDF</b>):

-


Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();

//Operation name of the web service. The web service is simple, input two numbers, and

// a flag/sign(+, -, *, /), then do the caculation...return the caculating result.

Node root = doc.appendChild(doc.createElementNS(

"urn:sap-com:document:sap:soap:functions:mc-style",

"ZtxiFmCaculator"));

root.appendChild(doc.createElement("FLAG").appendChild(doc.createTextNode(flag)));

root.appendChild(doc.createElement("NUM1").appendChild(doc.createTextNode(num1)));

root.appendChild(doc.createElement("NUM2").appendChild(doc.createTextNode(num2)));

String requestXml = doc.toString();

T_WSCHANNEL t_WSCHANNEL= new T_WSCHANNEL();

t_WSCHANNEL.setWSChannel("...", "...");//Channel has no any problem, I tested

//The following class follows all the lookup process, e.g. get channel,

//get SystemAccessor, and call for lookup...

T_WSLOOKUP_001 t_WSLOOKUP_001 = new T_WSLOOKUP_001();

String result = null;

return t_WSLOOKUP_001.myLookup(requestXml, t_WSCHANNEL);