1

I have a webservice that returns a Array of Arrays / jagged array.

I'm having problems to handle it in my local C# windows form app.

Initialy it was giving me Content Type error. Now with the sample bellow code, it's returning me a empty array.

I also tried to return a Single-dimensional array but the result is the same.

WebService Side:

    [WebMethod]
    public string[] teste()
    {
        string[] a = new string[1] { "one" };
        string[] b = new string[1] { "two" };
        string[][] c = { a, b };

        return c;
    }

Local Side:

class open_notes
{
    public static ServiceReference1.Smart_Stick_ServiceSoapClient web_service = new ServiceReference1.Smart_Stick_ServiceSoapClient();

    public static void open()
    {
        string[][] a = null;
        a [0][0] = web_service.teste().ToString();
        MessageBox.Show(a[0][0]);
    }
}

3 Answers 3

1

Your web service doesn't have a return type of string[][], you shouldn't call .ToString() on the result of the web service call, and you are accessing a null reference when you set string[][] a = null and then try to index to a[0][0]. Just set the variable to the result of the web service call

public static void open()
{
    var a = web_service.teste();
}
Sign up to request clarification or add additional context in comments.

Comments

1

Your function is returning an array of strings (opposed to an array of arrays of string) and you are calling ToString() on the resulting array.

Comments

-1

Thanks for the help guys

But In the end I think that is better to create a struct in the Web Service.

But you can't forget that instead creating again the struct in client side, you need to instanciate it, making a reference to the web service.

Server Side:

public struct ClientData

{
   public string descricao;
   public string timer;
}

[WebMethod]
    public ClientData[] teste()
    {
        ClientData[] Clients = null;
        Clients = new ClientData[30];

        Clients[0].descricao = "oi";
        Clients[0].timer = "legal";


        return Clients;
    }

Client Side:

public static void receive_teste()
    {

        WindowsFormsApplication1.ServiceReference1.ClientData[] Clients = null;
        Clients = new WindowsFormsApplication1.ServiceReference1.ClientData[30];

        Clients = (WindowsFormsApplication1.ServiceReference1.ClientData[])web_service.teste();

        MessageBox.Show(Clients[0].descricao.ToString()); // Shows returned "descricao"
        MessageBox.Show(Clients[0].timer.ToString()); // Shows returned "timer"

    }

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.