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. hdu1702 ACboy needs your help again![简单STL 栈 队列]

    目录 题目地址 题干 代码和解释 参考 题目地址 hdu1702 题干 代码和解释 本题很简单,只要掌握STL stack和STL vector的语法即可作答.记录本题是为了记录STL vector的 ...

  2. CS224n学习笔记(三)

    语言模型 对于一个文本中出现的单词 \(w_i\) 的概率,他更多的依靠的是前 \(n\) 个单词,而不是这句话中前面所有的单词. \[ P\left(w_{1}, \ldots, w_{m}\rig ...

  3. 如何在IDEA上配置Maven

    IDEA 全称 IntelliJ IDEA,是java语言开发的集成环境,IntelliJ在业界被公认为最好的Java开发工具之一, IDEA是JetBrains公司的产品,现在有逐步取代老牌Java ...

  4. PHP系列 | ThinkPHP5数据库迁移工具 migration

    了解更多,请关注微信公众号 ThinkPHP5数据库迁移工具 migration 什么是Migration? migration用谷歌翻译是移民的意思,在PHP中我们将它理解为迁移,将Migratio ...

  5. plupload如何限制上传文件数量,限制只能上传单个文件

    1 完整代码 $(function() { $("#uploader").pluploadQueue({ runtimes : 'html5,gears,flash,silverl ...

  6. jsoup获取标签下的文本(去除子标签的)

    jsoup获取标签下的文本(去除子标签的) <pre name="code" class="java">Element content=doc.se ...

  7. WebGL学习笔记(五):变换库

    在WebGL开始绘制之前,我们需要通过自己对3D空间进行矩阵和向量的运算,使用网上已经成熟的转换库,可以避免自己去实现这些复杂的数学运算. 我们这里选择的是gl-matrix库,下载地址:https: ...

  8. 003-maven开发Java脚手架archrtype-技术点说明

    一.概述 二.技术点说明 2.1.项目结构 凡auto包或文件件,均会被代码生成器再次生成二修改 1.model层 po:BasePO基础类,统一了数据库的基础字段[数据库必须添加如下,与mybati ...

  9. Java 枚举使用总结

    目录 1.枚举基础 1.1.创建枚举最简单的方式 1.2.简单使用 2.枚举的构造方法 2.1.使用注释方式说明 2.2.使用构造方法 2.3.使用带有构造器的枚举 3.就这些了? 3.1.需求 3. ...

  10. win10 启动后会自动恢复上次关机前的应用

    转载:https://www.v2ex.com/t/425101