开发者

How can I creating complexType variables in Coldfusion for use in SOAP request arguments?

开发者 https://www.devze.com 2023-03-28 02:04 出处:网络
UPDATE After perusing the docs some more I noticed that I left out the FieldArray and PropertyArray keys.So I no longer get the type mismatch error, but the SOAP request is still not right.

UPDATE


After perusing the docs some more I noticed that I left out the FieldArray and PropertyArray keys. So I no longer get the type mismatch error, but the SOAP request is still not right.

Here is the Error

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.... ''

Here is the revised Code

<cfscript>
function newField(Name, Type, IsNullable, Length, Precision, Scale) {
    s=StructNew();
    s["Name"]=argu开发者_开发问答ments.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>

Here is the SOAP XML request

<?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>

It now appears that despite the contents of the structures I am passing into the request as arguments, they are being considered null by Coldfusion for building the SOAP package.


ORIGINAL BELOW


I have a web service I am trying to access. The problem is that the methods defined by the WSDL have complexType arguments. In reality these complex types are actually quite simple structs and arrays, but I get the error

java.lang.IllegalArgumentException: argument type mismatch

Here is the WSDL link

http://tasks.arcgisonline.com/ArcGIS/services/Locators/TA_Address_NA_10/GeocodeServer?wsdl

Here is some documentation on the service

http://help.arcgis.com/en/arcgisserver/10.0/apis/soap/index.htm#SOAP_Geocode_GeocodeAddresses.htm

Here is the code I am trying to test this with

<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>


This is a really good place to get started with consuming complex datatypes with Coldfusion. They can be very tricky since you may need an array, an array of structs or a simple struct depending on item the WSDL.

http://tjordahl.blogspot.com/2008/04/reprint-consuming-web-service-complex.html (don't discard it because it's old - the information is still relevant event for CF9)

Generally, if there is more than one item, you will need to create an array, otherwise it's a struct. I've found you need to user str['key'] rather than str.key or str = {key=value} for structures since case sensitivity is only maintained with the first convention.

In my experience, it takes a lot of trial and error, especially if you have several items you are passing into the request.


You need to mirror the complex data type with CFC, see:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消