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



更新


在仔细阅读了这些文档之后,我注意到我遗漏了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在构建SOAP包时认为它们为null。


以下原件


我正在尝试访问一个web服务。问题是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>

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

http://tjordahl.blogspot.com/2008/04/reprint-consuming-web-service-complex.html(不要因为它是旧的而丢弃它——该信息仍然是CF9的相关事件(

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

根据我的经验,这需要大量的尝试和错误,尤其是如果你有几个项目要传递到请求中。

您需要用CFC镜像复杂的数据类型,请参阅:

http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7dbf.html

最新更新