【问题标题】:consuming coldfusion webservices使用coldfusion网络服务
【发布时间】:2012-05-05 13:40:43
【问题描述】:

我正在尝试构建 Web 服务。这是我返回字符串的简单 Web 服务的代码。 一开始我插入了一些来自ben nadel的代码 它会自动刷新存根文件,否则在传递参数时会出错。

<cfcomponent 
    displayname="BaseWebService"
    output = "false"
    hint="This handles core web service features">


    <cffunction
        name="Init"
        access="public"
        returntype="any"
        output="false"
        hint="Returns an initialized web service instance.">

        <cfreturn THIS />
    </cffunction>

    <cffunction
        name="RebuildStubFile"
        access="remote"
        returntype="void"
        output="false"
        hint="Rebuilds the WSDL file at the given url.">

        <cfargument name="Password" type="string" required="true" default="" />

        <cfif NOT Compare(ARGUMENTS.Password, "sweetlegs!")>
            <cfset CreateObject("java", "coldfusion.server.ServiceFactory"
                    ).XmlRpcService.RefreshWebService(
                        GetPageContext().GetRequest().GetRequestUrl().Append("?wsdl").ToString()) />
        </cfif>

        <cfreturn />
    </cffunction>

    <cffunction 
        name="easyService"
        access="remote"
        returntype="any"
        output="false">

        <cfargument name="anyOutput" type="string" default="this and that" />
        <cfargument name="xtype" type="string" required="yes" default="1" />        

            <cfif Compare(xtype, "1") EQ 0>
                <cfset anyVar = "one" />
            <cfelse>
                <cfset anyVar = "two" />

            </cfif>
        <cfreturn anyVar>       
    </cffunction>
</cfcomponent>

我在这里尝试调用网络服务。

<cfinvoke
    webservice="https://[...]/Components/Webservice.cfc?wsdl"
    method="RebuildStubFile">

    <cfinvokeargument 
        name="Password" 
        value="sweetlegs!" />
</cfinvoke>
<cfinvoke
    webservice="[...]/Components/Webservice.cfc?wsdl"
    method="easyService"
    returnVariable="anyVar" >

    <cfinvokeargument
        name="xtype"
        value="2" 
        omit="true">
</cfinvoke>

<cfdump var="#anyVar#">

可以调用我的 Web 服务组件的第一个方法,但第二个总是返回此错误消息:

coldfusion.xml.rpc.ServiceProxy$ServiceMethodNotFoundException: Web service operation     easyService with parameters {xtype={2}} cannot be found.
    at coldfusion.xml.rpc.ServiceProxy.invoke(ServiceProxy.java:149)
    at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2301)
    at coldfusion.tagext.lang.InvokeTag.doEndTag(InvokeTag.java:454)

如果我输入 web 服务的 url,通过添加

?method=easyService&xtype=2

它返回正确的值。但这就像使用 GET 方法传递值一样。

我已经搜索了几个小时,但不知道问题出在哪里。

【问题讨论】:

    标签: web-services coldfusion


    【解决方案1】:

    我认为在使用 WebService 调用时,您需要指定所有参数并在正确的参数上使用 omit="true"(而不是在 xtype 上)。

    <cfinvoke
        webservice="[...]/Components/Webservice.cfc?wsdl"
        method="easyService"
        returnVariable="anyVar" >
    
        <cfinvokeargument
            name="anyOutput"
            value=""
            omit="true">
    
        <cfinvokeargument
            name="xtype"
            value="2">
    </cfinvoke>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-15
      • 1970-01-01
      • 1970-01-01
      • 2010-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多