Coldfusion在PHP中使用SOAP Web服务

问题描述:

我有一个使用ZendSOAP在PHP中创建的webservice,URL如下: mysite.net/webservice/wsdl。该WSDL定义如下:Coldfusion在PHP中使用SOAP Web服务

<?xml version="1.0"?> 
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="mysite.net/webservice" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="Soap" targetNamespace="mysite.net/webservice"> 
    <types> 
     <xsd:schema targetNamespace="mysite.net/webservice" /> 
    </types> 
    <portType name="SoapPort"> 
     <operation name="cancelTrans"> 
      <documentation>Return cancel payment status</documentation> 
      <input message="tns:cancelTransIn" /> 
      <output message="tns:cancelTransOut" /> 
     </operation> 
    </portType> 
    <binding name="SoapBinding" type="tns:SoapPort"> 
     <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" /> 
     <operation name="cancelTrans"> 
      <soap:operation soapAction="mysite.net/webservice#cancelTrans" /> 
      <input> 
       <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="mysite.net/webservice" /> 
      </input> 
      <output> 
       <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="mysite.net/webservice" /> 
      </output> 
     </operation> 
    </binding> 
    <service name="SoapService"> 
     <port name="SoapPort" binding="tns:SoapBinding"> 
      <soap:address location="mysite.net/webservice" /> 
     </port> 
    </service> 
    <message name="cancelTransIn"> 
     <part name="transId" type="xsd:string" /> 
     <part name="transDate" type="xsd:string" /> 
     <part name="transAmount" type="xsd:string" /> 
     <part name="token" type="xsd:string" /> 
    </message> 
    <message name="cancelTransOut"> 
     <part name="return" type="xsd:string" /> 
    </message> 
</definitions> 

当我尝试使用ColdFusion将数据发送到Web服务,我得到了以下错误:

Detail Content is not allowed in prolog. 
ErrNumber 0 
ExceptionMessage Content is not allowed in prolog. 
Message  An error occurred while Parsing an XML document. 
StackTrace coldfusion.xml.XmlProcessException: An error occurred while Parsing an XML document. at coldfusion.xml.XmlProcessor.parse(XmlProcessor.java:287) at coldfusion.xml.XmlProcessor.parse(XmlProcessor.java:246) at coldfusion.runtime.CFPage.XmlParse(CFPage.java:265) at cfmain14870010962322d43b3f2622df2c72d561b2ddfec2d384dfba357452ecfm162910047.runPage(31EC38C4-A2D6-2A5C-5079916F7DB375F4:16) at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:251) at coldfusion.tagext.lang.IncludeTag.handlePageInvoke(IncludeTag.java:737) at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:573) at coldfusion.runtime.CfJspPage._emptyTcfTag(CfJspPage.java:3698) at cfcfmler2ecfc1489966816$func$RUNIT.runFunction(/home/webs/sbx/www/cfmler.cfc:159) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:492) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:388) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:339) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:234) at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:3544) at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:3524) at cfcfmler2ecfc1489966816$funcPLAYCFMFILE.runFunction(/home/webs/sbx/www/cfmler.cfc:79) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:492) at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:425) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:388) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:339) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:234) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:650) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:439) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:409) at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:3091) at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:3068) at cfgetremote2ecfm1955103781.runPage(/home/webs/sbx/www/getremote.cfm:78) at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:251) at coldfusion.tagext.lang.IncludeTag.handlePageInvoke(IncludeTag.java:737) at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:573) at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65) at coldfusion.filter.IpFilter.invoke(IpFilter.java:45) at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:484) at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:43) at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40) at coldfusion.filter.PathFilter.invoke(PathFilter.java:153) at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:30) at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:94) at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28) at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38) at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:60) at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38) at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22) at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62) at coldfusion.filter.RequestThrottleFilter.invoke(RequestThrottleFilter.java:151) at coldfusion.CfmServlet.service(CfmServlet.java:219) at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42) at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:536) at org.apache.coyote.ajp.AbstractAjpProcessor.process(AbstractAjpProcessor.java:898) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) 

我的ColdFusion代码如下:

<cfinvoke 
    method="cancelTrans" 
    returnvariable="rawXMLPaymentStatus" 
    webservice="mysite.net/webservice/wsdl"> 

    <cfinvokeargument name="token" value="ABCDEFG"> 
    <cfinvokeargument name="transAmount" value="30.15"> 
    <cfinvokeargument name="transDate" value="20170208"> 
    <cfinvokeargument name="transId" value="123456"> 

</cfinvoke> 

<cfset status = XmlParse(rawXMLPaymentStatus)> 

<cfdump var="#status#"> 

请帮忙吗?

谢谢。

+0

请问您能推荐一些代码吗? –

+0

(编辑)*我得到以下错误*听起来像您可能已启用自定义错误处理,所以它不显示真正的错误。假设这是你的DEV环境,暂时禁用它。否则,您将无法看到真实的错误消息。否则,将代码块包装在cftry/cfcatch中。在catch子句中转储错误并[编辑]您的问题以包含完整的错误消息。 [Trycf.com示例](http://trycf.com/gist/bd4c7978541a3e74d8aa129b75913e5a/acf2016?theme=monokai) – Leigh

+0

我编辑我的帖子与我正在使用的错误尝试catch谢谢 –

(从评论...)

An error occurred while Parsing an XML document

更新:然后响应不正是您期望(即不是有效的XML)。转储响应变量以查看它实际包含的内容,<cfdump var="#rawXMLPaymentStatus#">

与错误无关,但您可能希望查看使用createObject()来使用Web服务。它做的事情是一样的cfinvoke,但语法是多了几分紧凑:

<!--- create the web service instance ---> 
<cfset ws = createObject("webservice", "http://example.com/webservice/wsdl")> 
<!--- invoke the cancelTrans method with appropriate arguments ---> 
<cfset result = ws.cancelTrans("ABCDEFG", "30.15", "20170208", "123456")> 
<!--- display results ---> 
<cfdump var="#result#"> 

I get the following error: An error occurred while executing the application. Please try again or contact the administrator.

听起来像是你有启用自定义错误处理,所以应用程序是显示一个通用的消息,而不是真正的错误。假设这是你的DEV环境,暂时禁用它。否则,将很难排除故障,因为您无法看到真正的错误消息。否则,将代码块包装在cftry/cfcatch中。转储catch子句中的错误并编辑您的问题以包含完整的错误消息。 Trycf.com Example