Skip to main content
April 13, 2012
Question

Invoke webservice with complex types

  • April 13, 2012
  • 2 replies
  • 10228 views

Hi

I am trying to invoke a .net webservice method that receives an array of strings an i noticed that if i do this:

<cfscript>

     text = arraynew(1);

     text[1] = "Hello";

     text[2] = "world";

</cfscript>

<cfinvoke method="Hello"

  webservice="http://localhost/Service1.asmx?wsdl"

  returnvariable="response">

     <cfinvokeargument name="array" value=#text#/>

</cfinvoke>

I get this error

Cannot perform web service invocation Hello.

The fault returned when invoking the web service operation is:

''java.lang.IlligalArgumentException: argument type mismatch

however if i do this it works well:

<cfscript>

     root = structnew();

     text = arraynew(1);

     text[1] = "Hello";

     text[2] = "world";

     root.string=text;

</cfscript>

<cfinvoke method="Hello"

  webservice="http://localhost/Service1.asmx?wsdl"

  returnvariable="response">

     <cfinvokeargument name="array" value=#root#/>

</cfinvoke>

I know this has to do with the generated java proxy because he generated a structure called ArrayOfString with a property called string (what i am replicating in the "root" variable).... Is there any way around this, or this is the right way to do it? It is a bit painfull to do it like this...

Thanks.

    This topic has been closed for replies.

    2 replies

    Known Participant
    December 18, 2012

    Cool, how did you come up with root.string?  Trial and error??  I would love to know why root.string works.

    BKBK
    Community Expert
    Community Expert
    December 18, 2012

    henrylearn2rock wrote:

    Cool, how did you come up with root.string?  Trial and error??  I would love to know why root.string works.

    Your question seems irrelevant to this thread. Create your own thread, and you will surely get suggestions.

    BKBK
    Community Expert
    Community Expert
    April 14, 2012

    I can imagine that. Run the following code, and you will find that a ColdFusion array isn't a Java array at all, but a Java vector!

    <cfscript>

         text = arraynew(1);

         text[1] = "Hello";

         text[2] = "world";

    </cfscript>

    <cfoutput>

        text: #text.getClass().getsuperclass().getname()#

    </cfoutput>

    One of the methods of the java.util.Vector class is toArray(). So, have a go with

    <cfscript>

         text = arraynew(1);

         text[1] = "Hello";

         text[2] = "world";

         textArray = text.toArray();

    </cfscript>

    <cfinvoke method="Hello"

      webservice="http://localhost/Service1.asmx?wsdl"

      returnvariable="response">

         <cfinvokeargument name="array" value="#textArray#" />

    </cfinvoke>

    April 16, 2012

    Hi BFBK, thanks for your reply.

    I tried calling the toArray() but throws the same type mismatch error

    Dumping both the text and the textArray returns the same thing.

    Thanks.

    BKBK
    Community Expert
    Community Expert
    April 16, 2012

    Rockit8 wrote:

    I tried calling the toArray() but throws the same type mismatch error

    Sorry to hear that. We'll search on of course.

    Dumping both the text and the textArray returns the same thing.

    Not really. ColdFusion tells you they are both arrays, which is true. However, text is a ColdFusion array (a Java vector), whereas textArray is a Java Object array.

    <cfoutput>

        text: #text.getClass().getsuperclass().getname()#<br>

        textArray: #textArray.getClass().getname()#

    </cfoutput>