web-services - 如何在 Coldfusion 中使用经过身份验证的 Web 服务?

标签 web-services coldfusion wsdl

我正在使用网络服务(由于保密,我无法透露名称)。 Web 服务要求我在获得 wsdl 页面之前使用用户名和密码登录。例如,如果我在 Web 服务器中输入服务 url,它会提示我输入登录信息。

因此,我假设需要首先对自己进行身份验证,然后使用 wsdl。

但是,我编写了一些使用 w3schools 摄氏度到华氏度服务的测试代码,该代码不需要身份验证并且工作正常。

<!--- soap request in xml --->
<cfsavecontent variable="soap">
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" 
    xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" 
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
    xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" 
    xmlns:tns="http://www.w3schools.com/webservices/" 
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
    xmlns:s="http://www.w3.org/2001/XMLSchema" 
    xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" 
    xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" 
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
    <SOAP-ENV:Body>
        <tns:CelsiusToFahrenheit xmlns:tns="http://www.w3schools.com/webservices/">
            <tns:Celsius>34</tns:Celsius>
        </tns:CelsiusToFahrenheit>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
</cfsavecontent>

<!---Sending a post request accessing the defined SOAPAction CelsiusToFahrenheit--->
<cfhttp url="http://www.w3schools.com/webservices/tempconvert.asmx" method="post" result="httpresponse">
    <cfhttpparam type="header" name="content-type" value="text/xml"> 
    <cfhttpparam type="header" name="SOAPAction" value="""http://www.w3schools.com/webservices/CelsiusToFahrenheit"""> 
    <cfhttpparam type="header" name="content-length" value="#len(soap)#"> 
    <cfhttpparam type="header" name="charset" value="utf-8"> 
    <cfhttpparam type="xml" name="message" value="#trim(soap)#">  
</cfhttp>

<!---Output the result if http status is 200 (we can do error handling also) --->
<cfif find( "200", httpresponse.statusCode )>
    <cfset soapResponse = xmlParse(httpresponse.fileContent) />

    <cfset responseNodes = xmlSearch(soapResponse, "//*[ local-name() = 'CelsiusToFahrenheitResult' ]") />

    <cfoutput>Fahrenheit: #responseNodes[ 1 ].xmlText#</cfoutput>
</cfif>

我是否可以调整它来请求经过身份验证的网络服务?请注意这个问题可能有点含糊。不过,如果您需要更多信息,请发表评论让我知道。

编辑:当我调整网络服务的代码时,它说我握手失败。

编辑:添加了 wsdl 文件(更改了命名空间):[dump] http://dumptext.com/vy7Fj2da

最佳答案

握手失败可能有以下几个原因:

  1. 如果您使用的是 ColdFusion 9 或更早版本,您将发送 SSLv2 客户端问候以进行握手。最有可能的是,由于新的 PCI 法规,另一方已将其关闭,这就是您失败的原因。解决此问题的选项是:

    • 将 ColdFusion 升级到版本 10/11
    • 将当前 ColdFusion 的 Java 版本升级到 1.7
    • 使用以下不使用底层 Java 类的自定义标记来建立连接:cfx_http5 ( http://adiabata.com/cfx_http5.cfm )
  2. 另一方有一个 SSL 证书,您需要将其安装在 ColdFusion 存储中才能成功连接。像这样的事情:

    • keytool -importcert -v -alias [别名] -file [证书文件位置] -keystore D:\ColdFusion9\runtime\jre\lib\security\cacerts -storepass changeit

关于web-services - 如何在 Coldfusion 中使用经过身份验证的 Web 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33548398/

相关文章:

eclipse - 适用于 Eclipse 的 ColdFusion 9 行调试器

java - com.sun.xml.ws.message.saaj.SAAJHeader 无法转换为 com.sun.xml.ws.security.opt.impl.outgoing.SecurityHeader

php - 用于插入和查看数据库数据的 Web 服务

web-services - Delphi 2009 Web服务“xml文档必须具有顶层元素”

coldfusion - 为 ColdBox 应用程序创建数据源

apache-flex - 如何防止窥探者访问 CFC 中的 ="remote"功能?

java - 如何防止 cxf-codegen-plugin 为所有 wsdl 文件生成源

Java:WSDL Web服务wsimport,我需要重新运行wsimport吗?我更改了Web服务服务器中的@WebService类代码

java - 如何更新生成的 stub 的 XML-TYPE

web-services - 在外部为类创建 jaxb 注释