0

cfcを使用して、ASP.NETWebサービスデータをcoldfusionクエリオブジェクトに変換しています。jqueryコードでgetJSON呼び出しを使用して、そのクエリオブジェクトを返します。ただし、返されるデータはJSONデータセットではなくwddxパケットとしてフォーマットされており、コードが完了していないようです。何が間違っているのかわからない。

$(document).ready(function(){
    $("#submitForm").click(function(e){ 
        e.preventDefault();
        e.stopPropagation();
        internetUsage();
    });     
});

function internetUsage(){       
    $.getJSON("system.cfc",{
        method:'getInternetUsage',
        SessionID:$("#vSessionID").val(),
        CustomerCode:$("#vCustomerCode").val(),
        FullUserName:$("#selUser").val(),
        StartDate:$("#vStartDate").val(),
        EndDate:$("#vEndDate").val(),
        returnformat:'json',
        queryformat:'column'},function(res,code){

        alert('hello'); // THIS ALERT NEVER FIRES
    });
}

getInternetUsage()関数(下記)から返された善意の整形式クエリオブジェクトであることを確認できます。なぜそれがWDDXパケットとして届くのか途方に暮れています。

<cffunction name="getInternetUsage" access="remote" returnType="any" returnformat="JSON" output="false">
        <cfargument name="SessionID" required="true">
        <cfargument name="CustomerCode" required="true">
        <cfargument name="FullUserName" required="true">
        <cfargument name="StartDate" required="true">
        <cfargument name="EndDate" required="true">
        <cfargument name="entity" required="false" default="Table">
        <cfset var qResult = 0>
        <cfset var strWS = invokeInternetUsage(
                        SessionID=arguments.SessionID,
                        CustomerCode=arguments.CustomerCode,
                        FullUserName=arguments.FullUserName,
                        StartDate=arguments.StartDate,
                        EndDate=arguments.EndDate)>
        <cfset var aResult = convertDotNetDataset(strWS)>

        <--- extract the queries from the returned struct ---> 
        <cfif arguments.entity is 'Table'>
            <cfset qResult = aResult.Table>
        <cfelseif arguments.entity is 'Table1'>
            <cfset qResult = aResult.Table1>
        </cfif>
        <cfreturn qResult>
    </cffunction>

    <cffunction name="invokeInternetUsage" access="remote" returnType="any" output="false">
        <cfargument name="SessionID" required="true">
        <cfargument name="CustomerCode" required="true">
        <cfargument name="FullUserName" required="true">
        <cfargument name="StartDate" required="true">
        <cfargument name="EndDate" required="true">
        <cfset var aTemp = "">
        <cfinvoke 
            webservice="http://Portal/internet.asmx?WSDL"
            method="Usage"
            returnvariable="aTemp">
                <cfinvokeargument name="SessionID" value="#arguments.SessionID#"/>
                <cfinvokeargument name="CustomerCode" value="#arguments.CustomerCode#"/>
                <cfinvokeargument name="FullUserName" value="#arguments.FullUserName#"/>
                <cfinvokeargument name="StartDate" value="#arguments.StartDate#"/>
                <cfinvokeargument name="EndDate" value="#arguments.EndDate#"/>
        </cfinvoke>
        <cfreturn aTemp>
    </cffunction>


    <!--- convertDotNetDataset --->
    <!--- Converts a dotnet dataset into a structure of queries --->
    <cffunction name="convertDotNetDataset" access="remote" returnType="any" output="false"
            hint="takes a .Net dataset and converts it to a CF structure of queries">
    <cfargument name="dataset" required="true">
    <cfset var Local = StructNew()>
    <cfset Local.result = structNew() />
    <cfset Local.aDataset = arguments.dataset.get_any() />
    <cfset Local.xSchema = xmlParse(Local.aDataset[1]) />
    <cfset Local.xData = xmlParse(Local.aDataset[2]) />

    <!--- Create Queries --->
    <cfset Local.xTables = Local.xSchema["xs:schema"]["xs:element"]["xs:complexType"]["xs:choice"] />
    <cfloop from="1" to="#arrayLen(Local.xTables.xmlChildren)#" index="Local.i">
        <cfset Local.tableName = Local.xTables.xmlChildren[Local.i].xmlAttributes.name />
        <cfset Local.xColumns = Local.xTables.xmlChildren[Local.i].xmlChildren[1].xmlChildren[1].xmlChildren/>
        <cfset Local.result[Local.tableName] = queryNew("") />
        <cfloop from="1" to="#arrayLen(Local.xColumns)#" index="Local.j">
            <cfif left(Local.xColumns[Local.j].xmlAttributes.name,6) neq 'Column'>
                <cfset queryAddColumn(Local.result[Local.tableName], Local.xColumns[Local.j].xmlAttributes.name, arrayNew(1)) />
            </cfif>
        </cfloop>
    </cfloop>

    <!--- see if there are any row of data, if not exit --->
    <cfif NOT StructKeyExists(Local.xData["diffgr:diffgram"], "NewDataSet")>
        <cfreturn Local.result>
    </cfif>

    <!--- Populate Queries --->
    <cfset Local.xRows = Local.xData["diffgr:diffgram"]["NewDataSet"] />
    <cfloop from="1" to="#arrayLen(Local.xRows.xmlChildren)#" index="Local.i">
        <cfset Local.thisRow = Local.xRows.xmlChildren[Local.i] />
        <cfset Local.tableName = Local.thisRow.xmlName />
        <cfset queryAddRow(Local.result[Local.tableName], 1) />
        <cfloop from="1" to="#arrayLen(Local.thisRow.xmlChildren)#" index="Local.j">
            <cfif left(Local.thisRow.xmlChildren[Local.j].xmlName,6) neq 'Column'>
                <cfset querySetCell(Local.result[Local.tableName], Local.thisRow.xmlChildren[Local.j].xmlName, Local.thisRow.xmlChildren[Local.j].xmlText, Local.result[Local.tableName].recordCount) />
            </cfif>
        </cfloop>
    </cfloop>

    <cfreturn Local.result>
</cffunction>

編集-CFC

<cffunction name="invokeInternetUsage" access="remote" returnType="any" output="false">
    <cfargument name="SessionID" required="true">
    <cfargument name="CustomerCode" required="true">
    <cfargument name="FullUserName" required="true">
    <cfargument name="StartDate" required="true">
    <cfargument name="EndDate" required="true">
    <cfset var aTemp = "">
    <cftry>
        <cfinvoke 
            webservice="http://Portal/internet.asmx?WSDL"
            method="Usage"
            returnvariable="aTemp">
                <cfinvokeargument name="SessionID" value="#arguments.SessionID#"/>
                <cfinvokeargument name="CustomerCode" value="#arguments.CustomerCode#"/>
                <cfinvokeargument name="FullUserName" value="#arguments.FullUserName#"/>
                <cfinvokeargument name="StartDate" value="#arguments.StartDate#"/>
                <cfinvokeargument name="EndDate" value="#arguments.EndDate#"/>
        </cfinvoke>
        <cfcatch></cfcatch>
    </cftry>
    <cfreturn aTemp>
</cffunction>


<!--- convertDotNetDataset --->
<cffunction name="convertDotNetDataset" access="remote" returnType="any" output="false"
        hint="takes a .Net dataset and converts it to a CF structure of queries">
<cfargument name="dataset" required="true">
<cfset var Local = StructNew()>
<cfset Local.result = structNew() />
<cfset Local.aDataset = arguments.dataset.get_any() />
<cfset Local.xSchema = xmlParse(Local.aDataset[1]) />
<cfset Local.xData = xmlParse(Local.aDataset[2]) />

<!--- Create Queries --->
<cfset Local.xTables = Local.xSchema["xs:schema"]["xs:element"]["xs:complexType"]["xs:choice"] />
<cfloop from="1" to="#arrayLen(Local.xTables.xmlChildren)#" index="Local.i">
    <cfset Local.tableName = Local.xTables.xmlChildren[Local.i].xmlAttributes.name />
    <cfset Local.xColumns = Local.xTables.xmlChildren[Local.i].xmlChildren[1].xmlChildren[1].xmlChildren/>
    <cfset Local.result[Local.tableName] = queryNew("") />
    <cfloop from="1" to="#arrayLen(Local.xColumns)#" index="Local.j">
        <cfif left(Local.xColumns[Local.j].xmlAttributes.name,6) neq 'Column'>
            <cfset queryAddColumn(Local.result[Local.tableName], Local.xColumns[Local.j].xmlAttributes.name, arrayNew(1)) />
        </cfif>
    </cfloop>
</cfloop>

<!--- see if there are any row of data, if not exit --->
<cfif NOT StructKeyExists(Local.xData["diffgr:diffgram"], "NewDataSet")>
    <cfreturn Local.result>
</cfif>

<!--- Populate Queries --->
<cfset Local.xRows = Local.xData["diffgr:diffgram"]["NewDataSet"] />
<cfloop from="1" to="#arrayLen(Local.xRows.xmlChildren)#" index="Local.i">
    <cftry>
<cfset Local.thisRow = Local.xRows.xmlChildren[Local.i] />
        <cfset Local.tableName = Local.thisRow.xmlName />
        <cfset queryAddRow(Local.result[Local.tableName], 1) />
        <cfloop from="1" to="#arrayLen(Local.thisRow.xmlChildren)#" index="Local.j">
            <cfif left(Local.thisRow.xmlChildren[Local.j].xmlName,6) neq 'Column'>
                <cfset querySetCell(Local.result[Local.tableName], Local.thisRow.xmlChildren[Local.j].xmlName, Local.thisRow.xmlChildren[Local.j].xmlText, Local.result[Local.tableName].recordCount) />
            </cfif>
        </cfloop>
        <cfcatch></cfcatch>
    </cftry>
</cfloop>

<cfreturn Local.result>

4

3 に答える 3

3

サーバーで実行されている Coldfusion のバージョンは何ですか? CFMX7 とそれ以前のバージョンでは、cfc からの json の返しがサポートされていないことを知っています。私の経験では、CF が不明な戻り形式に遭遇した場合、デフォルト (wddx) を使用します。

于 2010-12-23T21:43:14.237 に答える
0

使用している ACF または Railo のバージョンをお知らせください。ACF8 には、リモート関数を呼び出すときに application.cfc の onrequest() メソッドを削除する必要があるというバグがあります。

http://www.raymondcamden.com/index.cfm/2009/7/13/ColdFusion-9-fixes-onRequest-adds-onCFCRequest

また、Chrome で開発者ツールを起動し、ajax リクエストから得られるレスポンスを調べる必要があります。

于 2012-11-30T01:13:26.350 に答える
0

これは CF8 および CF9 用です: CFFUNCTION で次を指定できます: returnFormat="json"

また、どの CFC 呼び出しでも、URL 変数 &return_format=json を追加できるはずです。

JSONを取得します

于 2010-12-27T18:37:33.993 に答える