1.开发 Web Services,编写cfcdemo.cfc组件,代码如下:  

<cfcomponent style ="document"
namespace = "http://www.mycompany.com/"
serviceportname = "RestrictedEmpInfo"
porttypename = "RestrictedEmpInfo"
bindingname = "myns:RestrictedEmpInfo"
displayname = "RestrictedEmpInfo"
hint = "RestrictedEmpInfo">
  <cffunction name = "getEname" access = "remote" returntype="xml" output="no" >
    <cfargument name = "dname" type = "string" required = "false">
    <cfargument name = "loc" type = "string" required = "false">
    <cfquery name = "dt" datasource = "scott">
      select * from dept where
      <cfif arguments.dname neq "">
        dname = #arguments.dname#
      </cfif>
    </cfquery>
    <cfxml variable="Books">
      <XML>
        <cfoutput query="rs">
          <book>
            <bname>#deptno#</bname>
            <isbn>#dname#</isbn>
            <writer>#loc#</writer>
          </book>
        </cfoutput>
      </XML>
    </cfxml>
    <cfreturn Books>
  </cffunction>
</cfcomponent>

 <!---
  ColdFusion开发 Web Services,只需要在ColdFusion组件(.cfc文件)中,
  把需要作为 Web Services 的method的access类型定义为remote就可以了(access="remote")。
 --->

2.测试一下,访问这个cfc组件,注意URL路径后边要加上 ?wsdl 。

eg:http://localhost/mysys/cfcdemo.cfc?wsdl 

显示效果如下:   

   3.开发测试页面,编写webservice.cfm程序调用①开发的 Web service ,代码如下:

   <cfset sWebServiceUrl = "http://localhost/cfcdemo.cfc?wsdl">
    <cfinvoke webservice="#sWebServiceUrl#"

      component = "cfcdemo"

      method = "getdept"

      returnVariable = "dept">
      <cfinvokeargument   name = "dname" value="10"/>   

      <!--- 访问参数,与参数值,对应.cfc中的  cfargument   ---> 
      <cfinvokeargument  name = "loc" value=""/>
    </cfinvoke>
   <cfdump var="#dept#">

4.说明:调用 Web Service 时,webservice.cfm部分和cfcdemo.cfc?wsdl对应如下:

  <cffunction></cffunction>   

  <!--- cfc组件中的方法,在cfcomponent中可以有多个  ---> 

  method -- 对应cfc组件中的方法,<cffunction>标签内name属性的值
  timeout -- 设置请求超时秒数
  returnVariable -- 自定义的变量,里边存放的是 Web Service 返回的值

 <!---传递参数--->                                                            
 <cfinvokeargument name="empno" value="7788"/> --

 <!---接收参数--->

<cfargument  name="empno" type="string" required="true">

<cfoutput>#dept#</cfoutput> -- 输出 Web Service

<!--- 注意返回类型一定要与 returntype 对应---> 

本文日期2018-11-08

文章参考博客anfslove 

ColdFusion 编写WebService 示例的更多相关文章

  1. ArcEngine编写WebService

    开发环境:Windows7旗舰版64bit.VisualStudio2008 With SP1.ArcEngine10.0.NetFrameWork4.0.IIS7和C#开发语言. 背景:ArcEng ...

  2. Selenium2学习-002-Selenium2 Web 元素定位及 XPath 编写演示示例

    此文主要对 Selenium2 的 Web 元素定位及 XPath 编写示例,敬请各位亲们参阅,共同探讨.若有不足之处,敬请各位大神指正,不胜感激! 通过 Firefox(火狐)浏览器的插件 Fire ...

  3. 使用RSA进行信息加密解密的WebService示例

    使用RSA进行信息加密解密的WebService示例 按:以下文字涉及RSA对WebService传递的数据的加密解密,如果您已经熟知RSA或是有其它更好的方法请不要往下看以免浪费时间. WebSer ...

  4. Delphi编写WebService体会

    源:Delphi编写WebService体会 Dispatch: 派遣,分派 Invoke: 调用 Invokable: 可调用接口 TReomtable: WebService中自定义类都是继承自该 ...

  5. delphi7编写客户端调用java服务器端webservice示例

    1. 首先取得java-webservice服务器端地址.我的是:http://localhost:8080/mywebservice/services/mywebservice?wsdl 2. 然后 ...

  6. AXIS2远程调用WebService示例(Eclipse+AXIS)

    转自:http://www.cnblogs.com/lanxuezaipiao/archive/2013/05/10/3071584.html 我们将Web Service发布在Tomcat或者其他应 ...

  7. Httpclient远程调用WebService示例(Eclipse+httpclient)

    package cn.com.taiji.pos.httpserver; import java.io.BufferedInputStream;import java.io.ByteArrayOutp ...

  8. LR编写webservice协议接口

    转自:http://lovesoo.org/use-loadrunner-call-webservice-interface-testing-optimization-summary.html 本文主 ...

  9. 使用Axis2编写webservice客户端,服务端

    1.编写客户端 Axis2开发WebService客户端 的3种方式 [参考帖子] http://blog.csdn.net/wangjinwei6912/article/details/851259 ...

随机推荐

  1. 20189220 余超《Linux内核原理与分析》第九周作业

    理解进程调度时机跟踪分析进程调度与进程切换的过程 本章的基础知识总结 一般来说,进程调度分为三种类型:中断处理过程(包括时钟中断.I/O 中断.系统调用和异常)中,直接调用schedule,或者返回用 ...

  2. MySQL服务问题

    Mysql使用命令 net start mysql net stop mysql 出现如下报错 经过查询得知可能是安装时修改过服务名称 查看服务名称的方法:这台电脑右键->管理->服务和应 ...

  3. 以SQL命令方式调用存储过程

    string str = "Data Source=.;Initial Catalog=***;Integrated Security=True"; using (SqlConne ...

  4. Multi-shot Pedestrian Re-identification via Sequential Decision Making

    Multi-shot Pedestrian Re-identification via Sequential Decision Making 2019-07-31 20:33:37 Paper: ht ...

  5. typescript - 1.环境搭建

    安装 1.安装node.js 安装typescript npm install -g typescript 3.编译 tsc helloworld.ts Typescript开发工具Vscode自动编 ...

  6. 企业微信域名IP列表

    https://res.mail.qq.com/zh_CN/wework_ip/latest.html?st=C98F886B96A94AD2207D9F0B2970B93DFD5A76DF94CED ...

  7. python初级(302) 3 easygui简单使用二

    一.复习 1.easygui 信息提示对话框 2.easygui 是否对话框 二.easygui其它组件 1.选择对话框:choicebox(msg, title, choices) import e ...

  8. mysql or条件查询优化

    当使用or的时候是不会用到索引的 explain SELECT * FROM aladdin_resource WHERE state = 1 OR state = 2; 解决办法就是用union替换 ...

  9. [LeetCode] 137. Single Number II 单独数 II

    Given a non-empty array of integers, every element appears three times except for one, which appears ...

  10. [LeetCode] 188. Best Time to Buy and Sell Stock IV 买卖股票的最佳时间 IV

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...