特定のタイプの関数に対して 2 つの異なる URL を持つ API を使用しています。1 つ目は、JSON または SOAP 要求をサポートするトランザクション API です。JSON 呼び出しのみを使用して、この API 内で必要なすべての関数を呼び出しましたが、すべてが完全に正常に機能しているようです。
2 つ目は、レポートの検索やダウンロードに使用されるレポート API です。この API は SOAP でのみ機能します。この API の機能を正しく動作させることができませんでした。会社のサポート グループに問い合わせてみましたが、ColdFusion での API 呼び出しを支援してくれる人がいません。この API とやり取りして関数にアクセスする 2 つの異なる方法を試みましたが、空になりました。以下は私の例と私が提供できる限りの情報です。当社のサービス プロバイダーの API および関連ドキュメントは機密情報ですが、私のコードに関係する特定の事柄に関するいくつかの質問にはお答えできます。
方法 1: Web サービス オブジェクトを作成します。
この SOAP 呼び出しを作成しようとした最初の方法は、Web サービス オブジェクトを使用することでした。メタデータ交換ポイントの URL を使用して、次のように createObject 関数に渡しました。
<cfset argStruct = structNew() />
<cfset argStruct['username'] = 'myusername' />
<cfset argStruct['password'] = 'mypassword' />
<cfset testSvc = createObject('webservice','https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex',argStruct) />
このコードを実行すると、次のエラー メッセージが表示されます。
Web サービス呼び出し用のスタブ オブジェクトを生成できません。名前: https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex . WSDL: https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex . javax.wsdl.WSDLException: WSDLException (/wsdl:definitions/wsdl:import): faultCode=OTHER_ERROR: 'https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex でインポートされたドキュメントを解決できませんか? wsdl=wsdl1'、'brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/' に対して: java.io.IOException: サーバーが HTTP 応答コードを返しました: URL の 401: https://brandnameapi.sandbox.serviceprovider. com/vernum/ReportingAPI.svc/mex?wsdl=wsdl1
401 エラーは一般的に不正な認証であるため、ブラウザで直接 URL を呼び出してアドレスを再確認しましたが、UN/PW でプロンプトが表示されました。値を入力すると、URL へのアクセスが許可され、次の XML が返されました。
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions name="ReportingAPI" targetNamespace="https://https://brandnameapi.serviceprovider.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:tns="https://https://brandnameapi.serviceprovider.com" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:i0="https://https://brandnameapi.serviceprovider.com/ReportingAPI/soapBinding" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<wsdl:import namespace="https://https://brandnameapi.serviceprovider.com/ReportingAPI/soapBinding" location="https://https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex?wsdl=wsdl1"/>
<wsdl:types/>
<wsdl:service name="ReportingAPI">
<wsdl:port name="BasicHttpBinding_IReportingAPI" binding="i0:BasicHttpBinding_IReportingAPI">
<soap:address location="https://https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/soap"/>
</wsdl:port>
</wsdl:service>
これは私が得た限りです。ブラウザで URL を呼び出して認証情報を渡すと、XML へのアクセスが許可されます。ColdFusion でこれを実行しようとすると、401 エラーが発生します。
方法 2: cfhttp リクエストの呼び出し
cfhttp を使用するように切り替えたところ、もう少し進んだように見えました。これを使用する場合:
<cfhttp url="https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex"
username="myusername" password="mypassword" method="get" result="httpResponse"
timeout="300">
</cfhttp>
httpResponse は適切なページ情報を返し、httpResponse.filecontent はブラウザで直接呼び出したときに受け取ったのと同じ XML を返します。
さらに一歩進んで、SOAP URL を取得し、利用可能なレポート ファイルのリストを返す API の関数を呼び出そうとしました。トランザクション API ですべての JSON 呼び出しに使用したのと同じ既知の作業プロセスを使用しました。
<cfhttp url="https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/soap/queryAvailableReportFiles"
username="myusername" password="mypassword" method="post"
result="httpResponse" timeout="300">
<cfhttpparam type="formfield" name="typeOfReport" value="DailyCSVFile" />
</cfhttp>
このコードを実行すると、ステータス コード 415 と、「コンテンツ タイプ 'application/x-www-form-urlencoded' が期待されるタイプ 'multipart/related; ではないため、メッセージを処理できません。type="application/xop+xml"'
cfhttps の間に次の行を追加すると:
<cfhttpparam type="header" name="Content-Type" value='multipart/related; type="application/xop+xml"' />
上記と同じエラーが発生しますが、ステータス コードが 400 に変わります。実行しようとしたすべてを含めたわけではなく、現在の場所のみを示します。できる限り多くの質問にお答えし、この問題の解決策を見つけるために指示に従って手順を再実行します.
更新:ご要望に応じて、フォーム フィールドではなく XML を渡すように cfhttp 呼び出しを変更しました。私の XML コードは、別の関数の API からの要求の生データの例を含む API ドキュメントから直接取得されます。
<cfsavecontent variable="soapBody">
<cfoutput>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<queryAvailableReportFiles
xmlns="https://brandnameapi.sandbox.serviceprovider.com/contract">
<fileName>DailyCSVFile</fileName>
</queryAvailableReportFiles>
</s:Body>
</s:Envelope>
</cfoutput>
</cfsavecontent>
<cfhttp url="https://prismproapi.sandbox.koretelematics.com/4/ReportingAPI.svc/soap/queryAvailableReportFiles" username="vfapi" password="bPzqQyK3" method="post" result="httpResponse" timeout="300">
<cfhttpparam type="xml" value="#trim(soapBody)#" />
</cfhttp>
公平を期すために、私がそれを正しく行っているかどうかはわかりません。そこから返されるエラー メッセージは、「To https://prismproapi.sandbox.koretelematics.com/4/ReportingAPI.svc/soap/queryAvailableReportFilesを含むメッセージは、EndpointDispatcher での AddressFilter の不一致により、受信者で処理できません。 。送信者と受信者の EndpointAddresses が一致していることを確認してください。」500エラーも発生します。