分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

ColdFusion 编写WebService 示例

发布时间:2023-09-06 02:21责任编辑:彭小芳关键词:Web

  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 示例

原文地址:https://www.cnblogs.com/JoinLi/p/9928335.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved