如何在Coldfusion中创建complexType变量以用于SOAP请求参数?

时间:2011-08-15 20:24:08

标签: soap coldfusion arcgis

更新


在仔细阅读文档后,我注意到我遗漏了FieldArray和PropertyArray键。所以我不再遇到类型不匹配错误,但SOAP请求仍然不正确。

这是错误

The fault returned when invoking the web service operation is:
AxisFault faultCode: {http://schemas.xmlsoap.org/soap/envelope/}client faultSubcode: faultString: Error processing server request faultActor: faultNode: faultDetail: {http://xml.apache.org/axis/}stackTrace:Error processing server request at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:221) at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:128) at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087) at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source) at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.... ''

以下是修订后的代码

<cfscript>
function newField(Name, Type, IsNullable, Length, Precision, Scale) {
    s=StructNew();
    s["Name"]=arguments.Name;
    s["Type"]=arguments.Type;
    s["IsNullable"]=arguments.IsNullable;
    s["Length"]=arguments.Length;
    s["Precision"]=arguments.Precision;
    s["Scale"]=arguments.Scale;
    return s;
}

function newRecord(oid, zipcode) {
    a=ArrayNew(1);
    ArrayAppend(a, arguments.oid);
    ArrayAppend(a, arguments.zipcode);
    return a;
}

function newKeyValue(key, value) {
    s=StructNew();
    s["Key"]=arguments.key;
    s["Value"]=arguments.value;
    return s;
}
</cfscript>


<cftry>

<cfscript>
ws = CreateObject("webservice", "http://tasks.arcgisonline.com/ArcGIS/services/Locators/TA_Address_NA_10/GeocodeServer?wsdl");
recordset=StructNew();
</cfscript>

<h1>GeocodeAddresses</h1>
<cfscript>
fields=StructNew();
fields["FieldArray"]=ArrayNew(1);
ArrayAppend(fields.FieldArray, newField("oid", "esriFieldTypeOID", false, 10, 0, 0));
ArrayAppend(fields.FieldArray, newField("zipcode", "esriFieldTypeString", true, 10, 0, 0));
recordset["Fields"]=fields;

records=ArrayNew(1);
ArrayAppend(records, newRecord(1,"33607"));
ArrayAppend(records, newRecord(2,"90210"));
recordset["Records"]=records;


mappings=StructNew();
mappings["PropertyArray"]=ArrayNew(1);
ArrayAppend(mappings.PropertyArray, newKeyValue("oid", "oid"));
ArrayAppend(mappings.PropertyArray, newKeyValue("Zip", "zipcode"));

propertys=StructNew();
propertys["PropertyArray"]=ArrayNew(1);
</cfscript>

<cfscript>
result = ws.geocodeAddresses(AddressTable=recordSet, AddressFieldMapping=mappings, PropMods=JavaCast("null", ""));
</cfscript>

<cfdump var="#ws#" label="#GetCurrentTemplatePath()#" />

<cfcatch>
    <cfdump var="#cfcatch#" label="#GetCurrentTemplatePath()#" />
    <cfdump var="#GetSOAPRequest(ws)#" label="#GetCurrentTemplatePath()#" />
    <cfdump var="#GetSOAPResponse(ws)#" label="#GetCurrentTemplatePath()#" />
</cfcatch>
</cftry>

这是SOAP XML请求

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
        <GeocodeAddresses xmlns="http://www.esri.com/schemas/ArcGIS/10.0">
            <AddressTable xmlns="" xsi:nil="true"/>
            <AddressFieldMapping xmlns="" xsi:nil="true"/>
            <PropMods xmlns="" xsi:nil="true"/>
        </GeocodeAddresses>
    </soapenv:Body>
</soapenv:Envelope>

现在看来,尽管我将结构的内容作为参数传递给请求,但Coldfusion将它们视为null,用于构建SOAP包。


以下原文


我正在尝试访问的网络服务。问题是WSDL定义的方法有complexType参数。实际上,这些复杂类型实际上是非常简单的结构和数组,但我得到了错误

java.lang.IllegalArgumentException: argument type mismatch

这是WSDL链接
http://tasks.arcgisonline.com/ArcGIS/services/Locators/TA_Address_NA_10/GeocodeServer?wsdl

以下是有关服务的一些文档
http://help.arcgis.com/en/arcgisserver/10.0/apis/soap/index.htm#SOAP_Geocode_GeocodeAddresses.htm

以下是我尝试使用

进行测试的代码
<cfscript>
function newField(Name, Type, IsNullable, Length, Precision, Scale) {
    s=StructNew();
    i=0;
    for(i in arguments){
        s[i]=arguments[i];
    }
    return s;
}

function newRecord(oid, zipcode) {
    a=ArrayNew(1);
    ArrayAppend(a, arguments.oid);
    ArrayAppend(a, arguments.zipcode);
    return a;
}

function newKeyValue(key, value) {
    s=StructNew();
    s["Key"]=arguments.key;
    s["Value"]=arguments.value;
    return s;
}
</cfscript>


<cftry>

<cfscript>
ws = CreateObject("webservice", "http://tasks.arcgisonline.com/ArcGIS/services/Locators/TA_Address_NA_10/GeocodeServer?wsdl");
recordset=StructNew();
</cfscript>
<cfdump var="#ws#" label="#GetCurrentTemplatePath()#" />

<h1>GeocodeAddresses</h1>
<cfscript>
fields=ArrayNew(1);
ArrayAppend(fields, newField("zipcode", "esriFieldTypeString", true, 10, 0, 0));
ArrayAppend(fields, newField("oid", "esriFieldTypeOID", false, 10, 0, 0));
recordset["Fields"]=fields;

records=ArrayNew(1);
ArrayAppend(records, newRecord(1,"90210"));
recordset["Records"]=records;


mappings=ArrayNew(1);
ArrayAppend(mappings, newKeyValue("zipcode", "Zip"));
</cfscript>

<cfdump var="#recordSet#" label="#GetCurrentTemplatePath()#" />
<cfdump var="#mappings#" label="#GetCurrentTemplatePath()#" />

<cfscript>
result = ws.geocodeAddresses(recordSet, mappings, JavaCast("null", ""));
</cfscript>

<cfdump var="#ws#" label="#GetCurrentTemplatePath()#" />

<cfcatch>
    <cfdump var="#cfcatch#" label="#GetCurrentTemplatePath()#" />
</cfcatch>
</cftry>

2 个答案:

答案 0 :(得分:1)

这是开始使用Coldfusion消耗复杂数据类型的一个非常好的地方。它们可能非常棘手,因为您可能需要一个数组,一个结构数组或一个简单的结构,具体取决于WSDL项。

http://tjordahl.blogspot.com/2008/04/reprint-consuming-web-service-complex.html(不要丢弃它,因为它已经过时了 - 这些信息仍然是CF9的相关事件)

通常,如果有多个项目,则需要创建一个数组,否则它是一个结构体。我发现你需要为结构使用str ['key']而不是str.key或str = {key = value},因为只有第一个约定才能保持区分大小写。

根据我的经验,这需要大量的试验和错误,特别是如果您有多个项目要传递给请求。

答案 1 :(得分:0)