`
wuhuizhong
  • 浏览: 681253 次
  • 性别: Icon_minigender_1
  • 来自: 中山
社区版块
存档分类
最新评论

calling a web service by plsql

阅读更多


Tom Krueger has an excellent write up on this:

I would like to say that calling a web service has been made easy with Sys.UTL_DBWS package but it took me a bit of time to get it right.  This biggest issue that I ran into is that the samples that I found online and in the forums simply don’t work.  

The sample below was provided by Oracle support and helped a lot in getting started so I thought that I would pass it along.  The sample uses a public web service so if the service is still running this code should just work for you.  My ultimate goal was to call a Microsoft WCF service which I have been able to do and plan to post the code soon.

function get_joke
return varchar2
is
  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
  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;


http://tomkrueger.wordpress.com/2008/09/17/how-to-call-a-web-service-from-oracle-plsql/



Also, there's another page that gives a good explanation of doing this:

Last day, a mission is given to me about calling a web services by pl/sql. Firstly, i started to search ; “What is a web service?” The term Web services describes a standardized way of integrating Web-basedapplications using the XMLSOAPWSDL and UDDI open standards over an Internet protocol backbone. Actually we can summarize it;

Web Services can convert your applications into Web-applications.
By using Web services, your application can publish its function or message to the rest of the world.

Web Services can be used by other applications.
With Web services your accounting department’s Win 2k servers can connect with your IT supplier’s UNIX server.

The basic Web Services platform is XML + HTTP.
Web services uses XML to code and decode your data and SOAP to transport it.

We have some input parameters and make a request. Then, we get a response from it with output parameters. All this syntax is in XML format. So, we will use XMLtype in our pl/sql package.

 

Let’s start to write a soap access package or we can use this package :) (www.oracle-base.com/dba/miscellaneous/soap_api.sql)

:) Let’s assume we have a function “myFunction” in this page http://www.mywebservice.com/web :)Then,start to write our code

 

 

 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,                                  'string1',                                  'partns:string',                                  vp_parameter1);                                            soap_api.add_parameter(ol_req,                                  'string2',                                  '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:n1"                                            vg_ws_address || '"');           END call_myfuntion;


END pkg_my_webservice; /


 

pkg_my_webservice_blog.txt

You may need to change some tag attributes. The main basic function syntax is like this. If you have more than one return xml tags, then you need to call the get_return_value function as much as result attributes. You may also store the results in a pl/sql type and return it back.

There are also other ways to do this. You may also use oracle’s “utl_dbws” package, however “utl_http” is more faster than it. You can test it.

In my next post, i am gonna explain soap_api package in more details.

 

 http://download-west.oracle.com/docs/cd/B12037_01/appdev.101/b10802/u_dbws.htm

 

 

 

 

 

分享到:
评论

相关推荐

    Building a JSON web service with Java and Axis2

    1.Download Axis2 as WAR and...7. Start your servlet container and test the standard version service by calling this url: http://localhost:8080/axis2/services/Version/getVersion?response=application/json

    PB web service

    描述 "Calling .NET Web Services from PB11.5" 提到的核心概念是,用户将学习如何在PowerBuilder中创建和消费.NET Web服务。这通常涉及到以下步骤: 1. **添加Web引用**:在PB中,开发者需要通过“项目”菜单选择...

    How to Use JS Calling A WebService By Post Both SOAP And JSON

    SOAP(Simple Object Access Protocol)和JSON(JavaScript Object Notation)是两种常见的数据交换格式,常用于Web服务通信。本文将详细介绍如何使用JavaScript通过POST方法调用SOAP和JSON Web服务。 首先,让我们...

    Amazon Web Services in Action(Manning,2015)

    You'll learn how to automate your infrastructure by programmatically calling the AWS API to control every part of AWS. Next, you'll learn options and techniques for storing your data. You'll also ...

    Python库 | joint-calling-0.1.88.tar.gz

    标题中的"Python库 | joint-calling-0.1.88.tar.gz"表明这是一个与Python相关的库,且版本号为0.1.88,它被打包成一个tar.gz文件。这种格式通常用于在Unix/Linux环境中分发软件,因为它可以进行文件压缩并合并多个...

    Calling Conventions Topics

    int __cdecl add(int a, int b); ``` 调用示例: ```c++ int result = add(5, 10); ``` 在这个例子中,参数 `10` 和 `5` 将按照从右到左的顺序被压入栈中,然后调用者需要清理栈。 #### Naked Function Calls ...

    ARASHI calling 歌词

    《ARASHI calling》是日本流行音乐团体ARASHI的一首歌曲,歌词中充满了积极向上的力量和对生命的执着追求。这首歌的主题围绕着把握现在、永不放弃和自我信念展开。 歌词中的“Calling”象征着呼唤,可能是对生活、...

    WebAssembly: Accessing C and C++ in Web Applications

    WebAssembly is a new, revolutionary technology that allows developers to program webpages using popular high-level languages like C, C++, Rust, and Python. Code is then compiled to WebAssembly ...

    Microsoft Teams Calling Solutions Calling Solutions.pdf

    Microsoft Teams Calling Solutions 知识点 Microsoft Teams Calling Solutions 是微软公司的一项电话解决方案,旨在帮助企业和中小型企业(SMB)提高通信效率,降低成本。根据 Forrester 的研究报告,本解决方案...

    Smoking_calling_train.zip

    本篇将详细探讨一个名为"Smoking_calling_train.zip"的数据集,它是一个专门用于训练AI模型,识别人们在吸烟时打电话这一复杂行为的宝贵资源。通过对这个数据集的理解和分析,我们可以更深入地了解AI在图像识别和...

    实验六:使用PLSQL编写存储过程访问数据库.ppt

    3. **将学生选课成绩从百分制改为等级制**:存储过程需能接收百分制成绩,根据设定的等级标准(如90-100为A,80-89为B等)返回相应的等级。这涉及到条件逻辑和字符串处理。 **实验要求** 学生需要按时完成实验内容...

    SAP FRC接口调用calling RFC_METADATA_GET -- see log for details报错解决方案

    SAP.Middleware.Connector.RfcCommunicationException:“destination XXXX failed when calling RFC_METADATA_GET -- see log for details” 猜测的原因: 老的DLL库在获取接口实例时,会触发“RFC_METADATA_GET”...

    arm smc calling convention

    ARM SMC调用规范文档(ARMDEN0028A)提供了关于如何正确使用SMC的详细指导。 #### 目的 - **确保安全通信**:通过定义标准化的调用约定,保证安全模式和非安全模式之间的交互安全可靠。 - **简化开发流程**:为...

    calling_conventions C++调用约定

    该文档描述了常见C++开发平台的调用约定,涉及到16位、32位、64位的程序开发,跨越Windows、Linux、BSD、Mac(基于Intel处理器)等操作系统,包含众多常用的编译器,同时文档也比较新,甚至谈论了AVX-512指令集。

    snp calling qul 算法

    本文将基于Heng Li等人发表的文章《一种统计框架用于基于测序数据的SNP调用、突变发现、关联映射及种群遗传参数估计》(A statistical framework for SNP calling, mutation discovery, association mapping and ...

    cad web预览

    cad web预览 工具 加载的方法需写在$(document).ready(function(){}) 中 加载转换的图纸文件 图纸文件是四个SVG/JS 文件,由 AutoXchange转换生成 下载地址:...

    web dynpro abap programming guidelines

    **1.8 使用参数调用Web Dynpro应用(Calling a Web Dynpro Application Using Parameters)** 通过在URL中添加特定的参数,可以控制应用程序启动时的状态或行为。 #### 二、跨组件编程(Cross-Component Programming) ...

    app-app-calling-android-master源码

    【app-app-calling-android-master源码】是一个针对Android平台的应用程序源码库,它提供了实现应用程序间通信(App-to-App Calling)的功能。这个源码项目对于开发者来说是一份宝贵的资源,可以帮助他们深入理解...

    11g_plsql_user_guide_and_reference.pdf

    Compound DML triggers allow multiple actions to be triggered by a single DML statement, such as INSERT, UPDATE, or DELETE. This feature simplifies the development of trigger-based business logic, ...

    GATK HaplotypeCaller SNP Calling 自动化流程

    基于GATK3.3以上版本的HaplotypeCaller标准流程进行,测试脚本以sra文件为最初输入,将读取文件见内的所有sra文件(视为同一个样本的数据),进行SNP Calling产生GVCF,然后用户可自行进行jointCall

Global site tag (gtag.js) - Google Analytics