Question

Best Way To Call Web Service From PL/SQL on 11g

Asked by: darren_k156

Hi,

Can someone please tell me the best way to call a remote web service from PL/SQL using Oracle 11g

Cheers

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-03-26 at 04:23:36ID23269966
Tags

oracle

,

Oracle 11g

,

11.1.0.6

Topics

Oracle 11.x Database

,

Oracle Database

,

PL / SQL

Participating Experts
3
Points
500
Comments
11

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. PL/SQL
    I cannot get either of these functions to work. I am a beginner with PL/SQL so I'm at a loss. Also I don't have means to any sort of debugger. I can't seem to get the following two functions to compile. Both of them return: Warning: Procedure created with compilation err...
  2. Oracle to PL/SQL conversion
    I am currently working on the conversion of PL/SQL script to T-SQL. I have certain issues that have come up correspondingly. The To_char function in Oracle can be converted to T-sql by using convert. But Convert needs three argumemnts when date has to be converted to charact...
  3. PL/SQL
    Hi, Is there a language just like PL/SQL for MYSQL? Is there an advanvantage to go with MYSQL over Oracle even if Oracle has the powerful PL/SQL language? Thanks, Pat
  4. using PL SQL
    I have a SQL server ( or even a MYSQL server avalable) I need to teach someone PL SQL but I don't have an oracle back end to use) Is there a frint end tool i can use to use PL SQL querires against another type of database cheers davoman
  5. PL/SQL
    Hi gurus, I'm learning how to use HTML DB. Is there a particular section for PL/SQL under Oracle in EE? Would you please intruduce some tutorial or book for a beginer to learn PL/SQL? Thanks for your reply, lilyyan

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: schwertnerPosted on 2008-03-26 at 06:15:52ID: 21211226

How to publish and consume a PL/SQL function as a Web Service using JDeveloper.

This note is for PL/SQL developers, starting with Web services technology and JDeveloper.

In this note, a PL/SQL function called "sayHelloWorld" is published as a Web Service.
Solution
Note that the PL/SQL function is a PL/SQL package function.
Create a PL/SQL function in the database.
Under SQL*Plus (under scott schema for example), enter the following code:
create or replace package HelloWorld
as
function sayHelloWorld (name IN VARCHAR2) return VARCHAR2;
end helloWorld;
/
show errors
create or replace package body HelloWorld as
function sayHelloWorld (name IN VARCHAR2) return VARCHAR2 is
begin

return( 'Hello '|| name );
end;
end helloWorld;
/
show errors
This will generate the function that will be exposed as a Web Service.
Create the Web Service using JDeveloper
1.      Start JDeveloper.
2.      Create a Database connection (call it "ORA92" for instance) related to the database where the function to publish has been declared. The connection's user must be the owner of the procedure (in this example scott), do not forget to select the check button "Deploy Password".
3.      Create a new Application called WebServicesPL containing an empty project called Project1.
4.      Right click on the project, and select New. In the General Gallery, select "Business Tier -> Web Services-> PL/SQL Web Service" and click on the OK button. The PL/SQL Web Service publishing Wizard is now started.
5.      First, you need to choose if you would like to create the Web Service as either a J2EE 1.4 or a J2EE 1.3 Web Service. Which one you choose is depending on which Application Server you later will deploy the Web Service to. As we in this example only uses the embedded OC4J container, we will choose "J2EE 1.4 (JAX-RPC) Web Service".
6.      If the Welcome page is displayed, then click on the Next button.
7.      On the Step 1 screen, select the Database connection that you have previously created ("ORA92"). Select the Database package from which the function belongs to: "HELLOWORLD". Leave the other options to their default values.
8.      In Step 2, just leave the default options as they are, and click Next.
9.      On the Step 3 screen, select the function "SAYHELLOWORLD", then click the Next button.
10.      In Steps 4 to 6, just leave the default options as they are, and click Next.
11.      In the Step 6 screen when you click on the Finish button, the Wizard will generate the necessary WSDL and Java files. It will also generate a Deployment profile that can be used to deploy the Web Service to an Application Server.
12.      Rebuild the project.
Test the Web Service within JDeveloper
1.      To build a client to test the Web services, right click on the Web Service and select 'Generate Web Service Proxy'.
2.      In the first step you choose if you would like the test client to connect to the embedded OC4J container, or to an external Application Server. In this example, we will use the 'Run against a service deployed to Embedded OC4J' option.
3.      This will create a Java client for the Web Service. You now just need to modify the code to include a call to the desired method(s), like:
System.out.println("calling " + myPort.getEndpoint());
myPort.sayhelloworld("test");
4.      Rebuild the project.
5.      Start the Web Service by right clicking on it and select 'Run'. This will start the Web Service on the embedded OC4J instance.
6.      The Web Service can be tested by using a Web Browser and point to the URL that is shown in the Embedded OC4J Log window:
http://localhost:8988/Application1-Project1-context-root/MyWebService2SoapHttpPort

7.      Run the Web Services client by selecting 'Run'. The output will be:
calling http://10.172.169.84:8988/Application1-Project1-context-root/MyWebService2SoapHttpPort
Hello test
Process exited with exit code 0.

Deploy the Web Service
1.      Create an Application Server connection to an OC4J server or an Application Server where the Web Service will be deployed.
2.      Right click on the WebServices.deploy node and select "Deploy to" option.
3.      Select the Application Server Connection related to the OC4J server / Application Server that was created in Step 1.
4.      The 'Configure Application Dialog' will appear, just use the default options here and click OK. This will start the deployment of the Web Service. Once it is finished, it can be accessed from the OC4J instance / Application Server.

 

by: darren_k156Posted on 2008-03-26 at 06:40:48ID: 21211445

Hi Schwertner,

I'm sorry but this isn't quite what I'm after. All I would like to do is to call a Web service (like the one in your comment) from a PL/SQL procedure in Oracle 11g.

It's probably simple to do but I can't find documentation on this anywhere!

 

by: sdstuberPosted on 2008-03-26 at 06:55:14ID: 21211618

Here's an example, from Tom Krueger's website

CREATE OR REPLACE FUNCTION get_joke
    RETURN VARCHAR2
AS
    service_             SYS.UTL_DBWS.service;
    call_                SYS.UTL_DBWS.CALL;
    service_qname        SYS.UTL_DBWS.qname;
    port_qname           SYS.UTL_DBWS.qname;
    xoperation_qname     SYS.UTL_DBWS.qname;
    xstring_type_qname   SYS.UTL_DBWS.qname;
    response             SYS.XMLTYPE;
    request              SYS.XMLTYPE;
BEGIN
--sys.utl_dbws.set_http_proxy('www-proxy:8080');
    service_qname    := SYS.UTL_DBWS.to_qname(NULL, 'getJoke');
    service_         := SYS.UTL_DBWS.create_service(service_qname);
    call_            := SYS.UTL_DBWS.create_call(service_);
    SYS.UTL_DBWS.set_target_endpoint_address
                        (call_,
                         'http://interpressfact.net/webservices/getjoke.asmx'
                        );
    SYS.UTL_DBWS.set_property(call_, 'SOAPACTION_USE', 'TRUE');
    SYS.UTL_DBWS.set_property(call_,
                              'SOAPACTION_URI',
                              'http://interpressfact.net/webservices/getJoke'
                             );
    SYS.UTL_DBWS.set_property(call_, 'OPERATION_STYLE', 'document');
    request          :=
        SYS.XMLTYPE
            ('<getJoke xmlns="http://interpressfact.net/webservices/"> <Category>Excuses-10</Category> </getJoke>'
            );
    response         := SYS.UTL_DBWS.invoke(call_, request);
    RETURN response.EXTRACT('//getJokeResult/child::text()',
                            'xmlns="http://interpressfact.net/webservices/"'
                           ).getstringval();
END;
/

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:

Select allOpen in new window

 

by: schwertnerPosted on 2008-03-26 at 08:30:01ID: 21212687

http://akdora.wordpress.com/2007/08/03/calling-a-web-service-by-plsql-utl_http/

This possibly will be interesting for you.

Alternativelly see

http://www.bloggingaboutoracle.org/archives/calling-web-services-from-plsql

CREATE OR REPLACE PACKAGE pkg_my_webservice IS
FUNCTION call_myfuntion
(
vp_parameter1 VARCHAR2,
vp_parameter2 VARCHAR2
) RETURN VARCHAR2;
END pkg_my_webservice;
/
CREATE OR REPLACE PACKAGE BODY pkg_my_webservice IS
 
vg_funciton_fnc VARCHAR2(256) := myFunction;
vg_ws_address VARCHAR2(255) := http://www.mywebservice.com/web;
 
FUNCTION call_myfuntion(
lets assume that it inputs two parameters called string1, string2
vp_parameter1 VARCHAR2,
vp_parameter2 VARCHAR2) 
 
RETURN VARCHAR2 AS
ol_req soap_api.t_request;
ol_resp soap_api.t_response;
BEGIN
 we initilize a new request
ol_req := soap_api.new_request(vg_funciton_fnc,
xmlns= || vg_ws_address || );
 we started to add parameters
soap_api.add_parameter(ol_req,
string12,
partns:string,
vp_parameter1);
soap_api.add_parameter(ol_req,
string22,
partns:string,
vp_parameter1);
 we call the web service
ol_resp := soap_api.invoke(ol_req,
vg_ws_address,
vg_funciton_fnc);
 we get back the results
RETURN soap_api.get_return_value(ol_resp,
result,  result tag name
xmlns:m= || can be change as xmlns:n13
vg_ws_address || );
 
END call_myfuntion;
 
END pkg_my_webservice;
/
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:

Select allOpen in new window

 

by: darren_k156Posted on 2008-03-26 at 08:30:20ID: 21212694

Hi,

I've tried something similar to the example you gave but have come unstuck on the installation of the package and am not up on Java enough to solve the problem...

I installed OC4J as per the instructions and tried to install the UTL_DBWS package but am getting an error when trying to install the package.

The instructions I'm following are on this page:
http://www.oracle-base.com/articles/10g/utl_dbws10g.php

The command that is falling over is:
loadjava -u system/mmcc -r -v -f -genmissing -s -grant public dbwsclientws.jar dbwsclientdb11.jar

Please see the attached screenshot of my command window for the errors

Any help is massively appreciated!!

 

by: sdstuberPosted on 2008-03-26 at 08:33:20ID: 21212721

do you have your ORACLE_SID defined?

either manually or by running oraenv?

 

by: darren_k156Posted on 2008-03-27 at 07:23:21ID: 21221635

Hi,

ORACLE_SID is not defined (in registry or as an environment variable) but I'm running this on a Windows box so didn't think I needed to set any environment variables...

Cheers

 

by: sdstuberPosted on 2008-03-27 at 07:25:35ID: 21221665

set it and try

 

by: talahiPosted on 2008-05-07 at 11:04:46ID: 21518874

I know this is a stupid question but I'm just starting on web services and trying to understand all that is involved in calling an external web service to update tables in my database (Oracle 10.2).  (I'm also using the Mensah book.) With the above example, how do I query this web service from sqlplus?

select jpub_plsql_wrapper.get_joke('  ') from dual?  
or
select utl_dbws.get_joke('  ') from dual?

I'm not sure how this is called or even what I'm calling from get_joke. Do I insert a joke string 'chicken crossed the road' and get the entire joke back?

 

by: sdstuberPosted on 2008-05-07 at 11:08:14ID: 21518902

get_joke takes no parameters


select get_joke from dual;

it will connect to the web service and retrieve one joke  the web service itself will decide which joke to give you

 

by: talahiPosted on 2008-05-07 at 11:31:04ID: 21519103

Thanks!

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...