Microsoft KB Archive/316273

= PRB: XML Web Service Created with ASP.NET Does Not Support Multidimensional Arrays =

Article ID: 316273

Article Last Modified on 2/11/2004

-

APPLIES TO


 * Microsoft ASP.NET 1.1
 * Microsoft Web Services Enhancements for Microsoft .NET 1.1
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft ASP.NET 1.0
 * Microsoft Web Services Enhancements for Microsoft .NET 2.0

-



This article was previously published under Q316273



SYMPTOMS
When you try to obtain a Web Services Description Language (WSDL) document from a Web service by using a Web service method that contains a return type or parameter type that is a multidimensional array, you receive the following HTML error message:

Cannot serialize object of type System.String[,]. Multidimensional arrays are not supported.

An exception is generated if you call the Web Service.



XML Web services that are created with ASP.NET do not support multidimensional arrays.



RESOLUTION
Instead of using multidimensional arrays, use the following code to specify an array of arrays (in other words, a jagged array): Visual C# .NET example:

[WebMethod] public string[][] ReturnMultiDimArray { string [] y = {&quot;ab&quot;,&quot;cd&quot;}; string [] z = {&quot;ef&quot;,&quot;gh&quot;}; string [][] x = {y,z}; return x; }

Visual Basic .NET example:

 Public Function ReturnMultiDimArray As String Dim y As String Dim z As String Dim x As String = New String {y, z} Return x End Function



STATUS
This behavior is by design.



Steps to Reproduce the Behavior
 Create an ASP.NET Web Service project.  Paste the following Web service method in WebService1.asmx.cs: Visual C# .NET example:

[WebMethod] public string[,] ReturnMultiDimArray {   string [,] x = new string[,] {{&quot;ab&quot;},{&quot;cd&quot;}} ; return x;  }

Visual Basic .NET example:

 Public Function ReturnMultiDimArray As String Dim x As String = New String {{}, {}} Return x  End Function  Build the Web Service. In Solution Explorer, right-click Service1.asmx.</li> Try to obtain a WSDL document from a Web Service.</li></ol>

Additional query words: kbnetsearch

Keywords: kbprb KB316273

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.