如何形成cfhttp调用以使用自定义Web服务API [英] How to form a cfhttp call to consume a custom webservice API

查看:93
本文介绍了如何形成cfhttp调用以使用自定义Web服务API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成为cf开发人员已有11年了,但不好意思说我对Web服务没有做任何实质性的事情。

I've been a cf developer for 11 years, but embarrassed to say that I've done nothing substantial with webservices.

如何形成cfhttp调用消耗供应商提供的以下Web服务API?

How to I form a cfhttp call to consume the following webservice API provided by the vendor?

Soap 1.2请求:

POST /Portal/internet.asmx HTTP/1.1
Host: 192.168.222.240
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <Usage xmlns="http://portal/internet.asmx">
      <SessionID>string</SessionID>
      <CustomerCode>int</CustomerCode>
      <FullUserName>string</FullUserName>
      <StartDate>dateTime</StartDate>
      <EndDate>dateTime</EndDate>
    </Usage>
  </soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

Soap 1.2响应:

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <UsageResponse xmlns="http://portal/internet.asmx">
      <UsageResult>
        <xsd:schema>schema</xsd:schema>xml</UsageResult>
    </UsageResponse>
  </soap12:Body>
</soap12:Envelope>

我现在想手动进行操作(我知道cfinvoke和createobject)。我从Ben Nadel博客中提出了以下内容,但出现连接失败错误。我想我只需要一个人来检查代码中明显的缺陷,然后再查看它是否与连接/授权真正相关。

I want to do it manually at the moment (I know about cfinvoke and createobject). I came up with the following from a Ben Nadel blog, but I get a "connection failure" error. I guess I just need someone to check for obvious flaws in the code before I look at whether it is genuinely connection/authorisation related.

<cfsavecontent variable="soapBody">
 <cfoutput>
  <?xml version="1.0" encoding="utf-8"?>
  <soap:Envelope 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
            xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
            xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
          <soap:Body>
            <Usage xmlns="http://portal/internet.asmx">
              <SessionID>F7B3B3FB-DE35-45CB-A785-8229E91FAEC9</SessionID>
              <CustomerCode>1112221</CustomerCode>
              <FullUserName>MR DAVE GEORGE</FullUserName>
              <StartDate>2010-01-01</StartDate>
              <EndDate>2009-01-01</EndDate>
            </Usage>
          </soap:Body>
        </soap:Envelope>

 </cfoutput>
</cfsavecontent>


<cfhttp
 url="http://portal/internet.asmx"
 method="post"
 result="httpResponse">

 <cfhttpparam
  type="header"
  name="SOAPAction"
  value="http://portal/internet.asmx/Usage"
  />

 <cfhttpparam
  type="header"
  name="accept-encoding"
  value="no-compression"
  />

 <cfhttpparam
  type="xml"
  value="#trim( soapBody )#"
  />

</cfhttp>



 <cfoutput>
 #httpResponse.fileContent# <!--- ouputs "connection failure" --->
    </cfoutput> 

非常感谢,
Paul

Many thanks, Paul

推荐答案

要相信,并不能用CF做到这一点,因为@Henry指出它是SOAP 1.2。因此,这似乎需要直接使用Java,尤其是Soap with Attachments API for Java(SAAJ)。它位于Java软件包 javax.xml.soap 中,该软件包不是标准Java发行版的一部分。而是从Oracle 单独下载

Going to take your word and assume cannot do it with CF because as @Henry pointed out it's SOAP 1.2. So looks like this requires using Java directly, specifically Soap with Attachments API for Java (SAAJ). This is in the java package javax.xml.soap, which is not part of a standard Java distribution. Instead it's a separate download from Oracle.

最好的结尾我可以找到有关的最终教程,其中包括建立与端点的连接,建立&发送请求以及接收和解析响应来自IBM的developerworks网站。请注意,它涉及其中,并且这样做需要从上述下载中在ColdFusion安装的类路径中安装几个jar。

Best end to end tutorial I could find on setting up a connection to an endpoint, building & sending a request, and receiving and parsing a response is from IBM's developerworks site. Be forewarned it's involved and doing so will require installing several jars in the ColdFusion installation's classpath from the aforementioned download.

这篇关于如何形成cfhttp调用以使用自定义Web服务API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆