Can be string array passed to and from an XML Web service?

A

Aras Kucinskas

Hi all,

The first methot of the sample code works well, the second returns an
error*.
Can be string array passed to and from an XML Web service?

==============
<WebMethod()> Public Function GetIntArray() As Integer()

Dim I As Integer
Dim A(4) As Integer
For I = 0 To 4
A(I) = I * 10
Next
Return A
End Function

<WebMethod()> Public Function GetStringsArray() As String()

Dim I As Integer
Dim A(4) As String
For I = 0 To 4
A(I) = (I * 10).ToString()
Next
Return A
End Function
============
* - error:
System.InvalidOperationException: There was an error generating the XML
document. ---> System.InvalidCastException: Specified cast is not valid.
at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write4
_ArrayOfString(Object o)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
Object o, XmlSerializerNamespaces namespaces, String encodingStyle)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter
textWriter, Object o)
at System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse
response, Stream outputStream, Object returnValue)
at System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[]
returnValues, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[]
returnValues)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
 
D

DalePres

I'm not sure of the VB syntax, but I return string arrays and arrays of
string arrays routinely in my web services.

Dale
 
S

Saurabh Nandu

I just copy pasted your code into a new service an it executes correctly. If you call the web service in IE, you will see that it returns the right results. What are you trying to do on the client end ?
 
A

Aras Kucinskas

The error:
===========
System.InvalidOperationException: There was an error generating the XML
document. ---> System.InvalidCastException: Specified cast is not valid.
at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write5
_ArrayOfString(Object o)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
Object o, XmlSerializerNamespaces namespaces, String encodingStyle)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter
textWriter, Object o)
at System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse
response, Stream outputStream, Object returnValue)
at System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[]
returnValues, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[]
returnValues)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
==============This error is returned then web service method is invoked from
IE. Nex code works well, but returns Object array.<WebMethod()> Public
Function GetStringsArray() As Object()Dim I As IntegerDim A(4) As StringFor
I = 0 To 4A(I) = (I * 10).ToString()NextReturn AEnd Function"Saurabh Nandu"
I just copy pasted your code into a new service an it executes correctly.
If you call the web service in IE, you will see that it returns the right
results. What are you trying to do on the client end ?
--
Regards,
Saurabh Nandu
Master C#, the easy way...
[ www.MasterCSharp.com ]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top