问题
I am trying to consume a WCF webservice.
<cfdump> shows the function as
getVwEmpByLocs(com.microsoft.schemas._2003._10.serialization.arrays.ArrayOfint)
UPDATE:
<cfset wsUser = createobject("webservice", "http://xxxxxxx/cardService.svc?wsdl")>
<cfdump var="#wsUser#">
<cfset locationID = []>
<cfset locationID[1] = 2092>
<cfset stResult = wsUser.GetVwEmpByLocs(javacast('int[]', locationID))>
Errors:
Message argument type mismatch
回答1:
After reading the comments from @Leigh and a little Google'ing I found the following article about Debugging ColdFusion Webservices. Of particular interest for this question (and what @Leigh was referring too) is the bullet item under number 2 (towards the bottom of the page). I will include that information here in case the referenced page is ever removed.
If you are getting a
java.lang.IllegalArgumentException: argument type mismatchwhile calling a .Net webservice withArrayOfIntorArrayOfStringas the argument type, then most probably you are not defining the datatypes correctly. TheArrayOfIntandArrayOfStringwill lead you to believe that .Net is expecting an Array. But remember ColdFusion arrays are not the same as .Net arrays. If you look at the wsdl carefully, you will notice that theArrayOfIntis defined as a complexType name.
<s:complexType name="ArrayOfInt">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="int" type="s:int" />
</s:sequence>
</s:complexType>
And complex types in CF are mapped to Structures. Further, you will notice that this complex type has an element with name="int". Now when java looks at the wsdl and creates the stub class files, its renaming this element to "_int". My guess is that its doing this because "int" is a reserved word in Java and also a native data type. So what this means is to successfully call the .Net webservice, you need:
<cfset objGroupIds = StructNew()>
<cfset objGroupIds._int = ListToArray("627303")>
<cfset callResult = myObj.getUser(objGroupIds)>
回答2:
First Look to the WSDL object of the service how the object serialized. create cf component name it ArrayOfInt.cfc
component displayname="ArrayOfint"
{
property name="int" type="Array" notnull="True" getter="false" setter="false";
this['int'] = ArrayNew(1);
function init(){ return this; }
}
pass values like this
arrOfInt = createobject('component','ArrayOfInt').init();
arrOfInt.int[1] = 100;
arrOfInt.int[2] = 200;
getVwEmpByLocs(arrOfInt)
回答3:
A couple of things that might help from a reference standpoint...
http://msdn.microsoft.com/en-us/library/kskex131%28v=vs.90%29.aspx Array data types are actually not predefined on the Array object in .Net, but by the datatype of the array elements.
http://msdn.microsoft.com/en-us/library/ff690589%28v=sql.105%29.aspx This is a basic schema which is defining the data type an array parameter can contain (e.g. ArrayOfInt). This appears to be defined by the wsdl schema.
Grasping at straws without being able to test, what if you create and pass an implicit array instead of trying to assign the value to a specific index. The other issue may be that you are trying to cast an array to a java int data type... not sure that this will work. May want to do the cast when assigning the value to the array.
<cfset stResult = wsUser.GetVwEmpByLocs([2092])>
or
<cfset locationID = [2092]>
<cfset stResult = wsUser.GetVwEmpByLocs(locationID)>
来源:https://stackoverflow.com/questions/14146897/consuming-a-wcf-webservice-with-arrayofint-paramenter