Microsoft Knowledge Base Email Alertz

(316273) - 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:...

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 316273 - Last Review: February 11, 2004 - Revision: 3.6

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

This article was previously published under Q316273

On This Page

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 = {"ab","cd"};
  string [] z = {"ef","gh"};			
  string [][] x = {y,z};			
  return x;
}

Visual Basic .NET example:

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

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Create an ASP.NET Web Service project.
  2. Paste the following Web service method in WebService1.asmx.cs:
       Visual C# .NET example:
    
       [WebMethod]
       public string[,] ReturnMultiDimArray()
       {
        string [,] x = new string[,] {{"ab"},{"cd"}} ; 
        return x;
       }
    
       Visual Basic .NET example:
    
       <WebMethod> Public Function ReturnMultiDimArray() As String(,)
        Dim x As String(,) = New String(,) {{}, {}}
        Return x
       End Function
    						
  3. Build the Web Service.
  4. In Solution Explorer, right-click Service1.asmx.
  5. Try to obtain a WSDL document from a Web Service.

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 (included with the .NET Framework) 1.0
Keywords: 
kbprb KB316273
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate