Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

web services - What should be used in ColdFusion to map to SOAP type tns:ArrayOfString?

If one cfinvoke a SOAP web service with param type sets to tns:ArrayOfString, one will get:

Cannot perform web service invocation Hello. The fault returned when invoking the web service operation is: ''java.lang.IlligalArgumentException: argument type mismatch

How to invoke a web service with type tns:ArrayOfString?

According to http://forums.adobe.com/message/4337438

This works:

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

now the question is, why does this work?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Like I mentioned in the thread you referenced, there is no direct mapping of ArrayOfString. So it is essentially treated as a structure, just like any other complex type. If you look at the wsdl, ArrayOfString contains a single key named string, whose value is an array of type="s:string":

<s:complexType name="ArrayOfString">
   <s:sequence>
     <s:element minOccurs="0" maxOccurs="unbounded" 
           name="string" nillable="true" type="s:string" /> 
   </s:sequence>
</s:complexType>

So the CF code works because it creates a structure with the correct key name (string) and value type (array of strings).

    root.string = [ arrayOfStrings ];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...