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. C# System.Web.Mail.MailMessage 发邮件

    C# System.Web.Mail.MailMessage 发邮件 新建控制台Console项目,然后添加 System.Web引用 代码如下: using System; using System ...

  2. python爬虫中XPath和lxml解析库

    什么是XML XML 指可扩展标记语言(EXtensible Markup Language) XML 是一种标记语言,很类似 HTML XML 的设计宗旨是传输数据,而非显示数据 XML 的标签需要 ...

  3. python2中的unicode()函数在python3中会报错:

    python2中的unicode()函数在python3中会报错:NameError: name 'unicode' is not defined There is no such name in P ...

  4. python 中requests的返回数可直接使用json

    对Python的request不是很了解,在使用时才发现,可以把request的请求结果,直接使用.json()['字段名']方法进行一个取值,案例如下 def test_tiantian(self) ...

  5. python:单例模式--使用__new__(cls)实现

    单例模式:即一个类有且仅有一个实例. 那么通过python怎么实现一个类只能有一个实例呢. class Earth: """ 假如你是神,你可以创造地球 "&q ...

  6. linux : 各个发行版中修改python27默认编码为utf-8

    该方法可解决robot报错:'ascii' codec can't encode character u'\xf1' in position 16: ordinal not in  range(128 ...

  7. .net MVC 项目中 上传或者处理进度获取方案

    首先讲下思路 就是利用js轮询定时的给后台发送数据 话不多说看代码 --------- 以下是相关方法 var t function timedCount() { $.ajax({ type: 'ge ...

  8. SOC中的DMIPS_GFLOPS_GMACS的含义

    l  DMIPS全称叫Dhrystone MIPS 这项测试是用来计算同一秒内系统的处理能力,它的单位以百万来计算,也就是(MIPS) 上面的意思也就是,这个处理器测整数计算能力为(200*100万) ...

  9. android基础---->SharedPreferences的使用

    SharedPreferences 还支持多种不同的数据类型存储,如果存储的数据类型是整型,那么读取出来的数据也是整型的,存储的数据是一个字符串,读取出来的数据仍然是字符串.这样你应该就能明显地感觉到 ...

  10. Java-Initialization

    package interfaces.music; abstract class Base{ Base(){ print(); } public abstract void print(); } cl ...