我一直是一個cf開發人員11年,但不好意思說我沒有做任何實質性的web服務。如何形成一個cfhttp調用來使用自定義的webservice API
如何形成一個cfhttp調用來使用供應商提供的以下webservice API?
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博客提出以下內容,但是我收到了「連接失敗」錯誤。我想我只是需要有人來檢查代碼中是否存在明顯的缺陷,然後再查看它是否真正與連接/授權相關。
<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>
非常感謝, 保羅
嗨保羅,只想說:有什麼好尷尬的。我也用了12年的CF,很多我不知道,而且我每天都在學習很多東西。這是關於CFML的其中一件事情......你可以到現在爲止,而無需詢問,學習或排除故障,最終有時會在多年後結束! – 2010-12-09 00:21:08
SOAP 1.2是一團糟,尤其是當CF僅支持1.1 AFAIK – Henry 2010-12-09 01:26:35