S
Srikanth Subramanian
All,
I'm having a problem with a VS.NET generated SOAP client that
connects to an existing Web service. The problem is that
the Web service is returning a single dimensional Array of strings,
but without an arrayType attribute. The .NET client fails to
deserialize the array content. My question is: Does .NET require
the "arrayType" attribute to be specified to be able to deserialize
an array ?
Here is the relevant portion of WSDL:
<types>
....
<xsd:complexType name="array">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0"
name="value"
type="xsd:string"/>
</xsd:sequence>
<xsd:attribute ref="SOAP-ENC:arrayType"
wsdl:arrayType="xsd:string
[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</types>
<message name="searchResponse">
<part name="return" type="tns:array"/>
</message>
<portType name=...>
<operation name="search">
<input message="tns:search"/>
<output message="tns:searchResponse"/>
</operation>
</portType>
The generated proxy class has a method of the form:
string[] search(...)
{
}
Here is the SOAP response message received from the Web service:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="salesforce" xmlns:types="salesforce/encodedTypes"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<soap:Header/>
<soap:Body>
<return>
<valueArray xsi:type="tns:array">
<value xsi:type="xsd:string">abcd</value>
</valueArray>
</return>
</soap:Body>
</soap:Envelope>
If you notice, the encoded array (valueArray) in the SOAP message,
does not have the arrayType attribute (which according to spec, is
obligatory).
I get the following error:
Unhandled Exception: System.InvalidOperationException: There is an
error in XML
document (1, 423). ---> System.InvalidCastException: Cannot assign
object of typ
e System.Xml.XmlNode[] to an object of type System.String[].
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read
34_searchResponse()
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader
xmlReader)
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClie
ntMessage message, WebResponse response, Stream responseStream)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String
methodN
ame, Object[] parameters)
at sf.localhost6.sfconnector.search(String type, String scope,
String searchV
alue, Int32 maxRows) in c:\dev\sf\web
references\localhost6\reference.cs:line 21
4
at sf.Class2.Main(String[] args) in c:\dev\sf\class2.cs:line 127
Why is .NET not able to deserialize this array into a string[] ?
I have tried playing with the WSDL type specification for the custom
"array" type, but with no success - everytime the .NET client throws
an exception about being unable to assign to a string[].
Any help would be appreciated. Thanks !
-Srikanth
I'm having a problem with a VS.NET generated SOAP client that
connects to an existing Web service. The problem is that
the Web service is returning a single dimensional Array of strings,
but without an arrayType attribute. The .NET client fails to
deserialize the array content. My question is: Does .NET require
the "arrayType" attribute to be specified to be able to deserialize
an array ?
Here is the relevant portion of WSDL:
<types>
....
<xsd:complexType name="array">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0"
name="value"
type="xsd:string"/>
</xsd:sequence>
<xsd:attribute ref="SOAP-ENC:arrayType"
wsdl:arrayType="xsd:string
[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</types>
<message name="searchResponse">
<part name="return" type="tns:array"/>
</message>
<portType name=...>
<operation name="search">
<input message="tns:search"/>
<output message="tns:searchResponse"/>
</operation>
</portType>
The generated proxy class has a method of the form:
string[] search(...)
{
}
Here is the SOAP response message received from the Web service:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="salesforce" xmlns:types="salesforce/encodedTypes"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<soap:Header/>
<soap:Body>
<return>
<valueArray xsi:type="tns:array">
<value xsi:type="xsd:string">abcd</value>
</valueArray>
</return>
</soap:Body>
</soap:Envelope>
If you notice, the encoded array (valueArray) in the SOAP message,
does not have the arrayType attribute (which according to spec, is
obligatory).
I get the following error:
Unhandled Exception: System.InvalidOperationException: There is an
error in XML
document (1, 423). ---> System.InvalidCastException: Cannot assign
object of typ
e System.Xml.XmlNode[] to an object of type System.String[].
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read
34_searchResponse()
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader
xmlReader)
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClie
ntMessage message, WebResponse response, Stream responseStream)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String
methodN
ame, Object[] parameters)
at sf.localhost6.sfconnector.search(String type, String scope,
String searchV
alue, Int32 maxRows) in c:\dev\sf\web
references\localhost6\reference.cs:line 21
4
at sf.Class2.Main(String[] args) in c:\dev\sf\class2.cs:line 127
Why is .NET not able to deserialize this array into a string[] ?
I have tried playing with the WSDL type specification for the custom
"array" type, but with no success - everytime the .NET client throws
an exception about being unable to assign to a string[].
Any help would be appreciated. Thanks !
-Srikanth