I am trying to use the Java web service, but getting an exception. System.InvalidCastException: cannot assign an object of type ValueArrayType to an object of type ValueArrayType []
I consume a third-party service, so I canβt change the service and was informed that they can use the service with php and java.
Array type is a complex type
<xsd:complexType name="ValueArrayType"> <xsd:sequence> <xsd:element name="ValueName" type="xsd:string"/> <xsd:element name="ValueType" type="xsd:string"/> <xsd:element name="ValueValue" type="xsd:string"/> </xsd:sequence> </xsd:complexType>
This is an element in the response's DetailsType file that can have multiple occurrences, as it has max = unbound and is wrapped with a sequence attribute.
<xsd:complexType name="DetailsType"> <xsd:sequence> <xsd:element name="Id" type="xsd:int"/> <xsd:element name="MobileName" type="xsd:string"/> <xsd:element name="ValueArray" type="tns:ValueArrayType" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType>
I tried wsdll.exe and svrcutil.exe to try to create client code. ValueArrayType is defined in the generated code as an array.
public ValueArrayType[] ValueArray { get { return this.valueArrayField; } set { this.valueArrayField = value; } }
an example of the returned data.
.... <Details xsi:type="tns:DetailsType"> <Id xsi:type="xsd:int">9999</Id> <ValueArray xsi:type="tns:ValueArrayType"> <ValueName xsi:type="xsd:string">Count</ValueName> <ValueType xsi:type="xsd:string">numeric</ValueType> <ValueValue xsi:type="xsd:string">11</ValueValue> </ValueArray> <ValueArray xsi:type="tns:ValueArrayType"> <ValueName xsi:type="xsd:string">Start</ValueName> <ValueType xsi:type="xsd:string">numeric</ValueType> <ValueValue xsi:type="xsd:string">31</ValueValue> </ValueArray> <ValueArray xsi:type="tns:ValueArrayType"> <ValueName xsi:type="xsd:string">A1</ValueName> <ValueType xsi:type="xsd:string">numeric</ValueType> <ValueValue xsi:type="xsd:string">23</ValueValue> </ValueArray> <ValueArray xsi:type="tns:ValueArrayType"> <ValueName xsi:type="xsd:string">A2</ValueName> <ValueType xsi:type="xsd:string">numeric</ValueType> <ValueValue xsi:type="xsd:string">0</ValueValue> </ValueArray> <ValueArray xsi:type="tns:ValueArrayType"> <ValueName xsi:type="xsd:string">X1</ValueName> <ValueType xsi:type="xsd:string">numeric</ValueType> <ValueValue xsi:type="xsd:string">0</ValueValue> </ValueArray> .....
If I change the client code to a public ValueArrayType ValueArray instead of an array, then the client works, but only the first ValueArray is received.
Tried suggestions from http://blogs.msdn.com/b/netcfteam/archive/2007/02/01/why-your-netcf-apps-fail-to-call-some-web-services.aspx .
Refresh
I created a WCF service with proxyclass generated from scvutil. When I use and check xml with WCFTestCLient.exe.
The array type is sent back as
<ValueArray> <ValueArrayType> <ValueName>a</ValueName> <ValueType>string</ValueType> <ValueValue>1</ValueValue> </ValueArrayType> <ValueArrayType> <ValueName>a</ValueName> <ValueType>string</ValueType> <ValueValue>2</ValueValue> </ValueArrayType> </ValueArray>
I assume that either the data sent does not match the WSDL, or an error appears in Cvvulil or System.ServiceModel.