0

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

Leigh
  • 28,765
  • 10
  • 55
  • 103
James A Mohler
  • 11,060
  • 15
  • 46
  • 72
  • Like Shirak said, take a look the wdsl definition. IIRC it is similar to `ArrayOfString` (just with `int` instead of `string`), so [this thread might help](http://stackoverflow.com/questions/13941422/what-should-be-used-in-coldfusion-to-map-to-soap-type-tnsarrayofstring). – Leigh Jan 03 '13 at 21:26
  • 1
    I cannot test it right now, but essentially do something like this `someStructure.int = [cf array of integers];` – Leigh Jan 03 '13 at 21:34
  • [See this post, specifically the bullet under number 2 regarding ArrayOfInt with .NET services](http://blog.daksatech.com/2011/04/debugging-coldfusion-webservices.html) – Miguel-F Jan 03 '13 at 21:42
  • @Miguel-F - Yep, that is essentially what I described in the other thread. I think it should work if you create a structure with the key `int` which contains an array of integers. (Edit) Shirak's approach may work as well, but a using a plain structure is simpler. – Leigh Jan 03 '13 at 21:46
  • @Miguel-F - This one worked, and I like that it is simpler Shirak's solution – James A Mohler Jan 04 '13 at 16:38
  • Credit goes to @Leigh, I was just trying to help explain her point. Glad it worked for you! – Miguel-F Jan 04 '13 at 16:43
  • @Miguel-F - Looking closer I think the blog entry uses `_int` rather of `int`. So it is possible *your* answer is the correct one ;-) If so, you should post it as an answer for the archives. – Leigh Jan 04 '13 at 16:57
  • @Leigh - I'm not sure which version actually worked for the OP. Whether he used `_int` or `int`? Either way I agree with you that an answer should be posted so others finding this can see it more readily. – Miguel-F Jan 04 '13 at 17:03
  • @Miguel-F - I have a vague recollection that it might be `_int` .. but it has been a while. Go ahead and post it as an answer. You can always update the answer (if needed). – Leigh Jan 04 '13 at 17:23

3 Answers3

1

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)
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 mismatch while calling a .Net webservice with ArrayOfInt or ArrayOfString as the argument type, then most probably you are not defining the datatypes correctly. The ArrayOfInt and ArrayOfString will 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 the ArrayOfInt is 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)>
Miguel-F
  • 13,450
  • 6
  • 38
  • 63
0

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)>
bphillips
  • 459
  • 2
  • 5