Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
498 views
in Technique[技术] by (71.8m points)

coldfusion - Why is a SOAP call working from CFM page but not from a CFC page?

I am working with a SOAP request in coldfusion. When the code I have is run from a .CFM file, it works. If it is run from a .CFC file, it doesn't work. The code is the same as far as possible (the .CFC needs the cfcomponent and cffunction tags for example).

Why would it work from one and not the other? When I call it from the CFC page I get the error

Error message

Does anyone have any idea why this might be happening? The SOAP request is identical on both pages. The call with the CFHTTP as well as all the CFHTTPPARAMs are the same as well.

Here is the code for the CFC file:

<cfcomponent>
    <cffunction name="updateAgParcel" returntype="string" returnformat="plain" access="remote">
        <cfargument name="ag_pres_nr" required="true" type="string">
        <cfargument name="emp_nr" required="true" type="string">
        <cfargument name="dt_rcvd" required="true" type="string">
        <cfset dt_rcvd = DateFormat(#dt_rcvd#,"MMDDYYYY")>
        <cfsavecontent variable="soapBody">
            <cfoutput>
                <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ass="http://XXXXXX">
                   <soapenv:Header/>
                   <soapenv:Body>
                      <ass:LogAgPreserveFiling>
                            <ass:AG.PRES.NR>#ag_pres_nr#</ass:AG.PRES.NR>
                            <ass:TC>04</ass:TC>
                            <ass:EMP.NR>#emp_nr#</ass:EMP.NR>
                            <ass:LCAQ.DT.RCVD>#dt_rcvd#</ass:LCAQ.DT.RCVD>
                            </ass:LogAgPreserveFiling>
                    </soapenv:Body>
                </soapenv:Envelope>
            </cfoutput>
        </cfsavecontent>

        <cfhttp url="XXXXXXXXXXXXXXX" method="post" result="httpResponse">
            <cfhttpparam type="header" name="SOAPAction" value="XXXXXXXXXXXX" />
            <cfhttpparam type="header" name="Authorization" value="Basic XXXXXXXXXXXXXX" />
            <cfhttpparam type="header" name="accept-encoding" value="no-compression" />
            <cfhttpparam type="header" name="Content-Type" value="text/xml" />
            <cfhttpparam type="xml" value="#trim( soapBody )#" />
        </cfhttp>

        <cfif find( "200", httpResponse.statusCode )>
            <cfset soapResponse = xmlParse( httpResponse.fileContent ) />
            <cfset responseNodes = xmlSearch(soapResponse, "//*[ local-name() = 'VCfaultdetails'] ") />
            <cfif arrayLen(responseNodes) NEQ 0>
                <cfset error = #responseNodes[ 1 ].message.xmlText#>
                <cfreturn error>
            <cfelse>
                <cfreturn "">
            </cfif>
        </cfif>
    </cffunction>
</cfcomponent>

Code for the CFM version:

<cfsavecontent variable="soapBody">
    <cfoutput>
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ass="http://XXXXX">
           <soapenv:Header/>
           <soapenv:Body>
              <ass:LogAgPreserveFiling>
                   <ass:AG.PRES.NR>#ag_pres_nr#</ass:AG.PRES.NR>
                   <ass:TC>04</ass:TC>
                   <ass:EMP.NR>#emp_nr#</ass:EMP.NR>
                   <ass:LCAQ.DT.RCVD>#dt_rcvd#</ass:LCAQ.DT.RCVD>
              </ass:LogAgPreserveFiling>
           </soapenv:Body>
        </soapenv:Envelope>
    </cfoutput>
</cfsavecontent>

<cfhttp url="XXXXXXXXXXXXX" method="post" result="httpResponse">
    <cfhttpparam type="header" name="SOAPAction" value="XXXXXXXXXXXXXXX"/>
    <cfhttpparam type="header" name="content-type" value="text/xml">
    <cfhttpparam type="header" name="Authorization" value="Basic XXXXXXXXXXXXXXXXX" />
    <cfhttpparam type="header" name="accept-encoding" value="no-compression" />
    <cfhttpparam type="xml" value="#trim( soapBody )#" />
</cfhttp>


<cfif find( "200", httpResponse.statusCode )>
    <cfset soapResponse = xmlParse( httpResponse.fileContent ) />
    <cfset responseNodes = xmlSearch( soapResponse, "//*[ local-name() = 'VCfaultdetails'] " ) />
    <cfif arrayLen(responseNodes) NEQ 0>
    <cfoutput>
        Code: #responseNodes[ 1 ].errorcode#
        <br />
        Message: #responseNodes[ 1 ].message#
    </cfoutput>
    <cfelse>
        Success!!!!!!!!
    </cfif>
</cfif>

I XXXXXX out some of the URL's and such for security. Also, sorry for the namespace the developers choose (ass:). It was the abbreviation for Assessor. Somebody was being funny...

question from:https://stackoverflow.com/questions/65925000/why-is-a-soap-call-working-from-cfm-page-but-not-from-a-cfc-page

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...