ceth
ceth

Reputation: 45295

Web service client type casting

It is my first experience with .net, so the question can be simple. I have the Web Method of Web Service:

[WebMethod(CacheDuration = 30,
            Description = "Returns an Array of Clients.")]
        public ClientData[] GetClientData(int Number)
        {
            ClientData[] Clients = null;

            if (Number > 0 && Number <= 10)
            {
                Clients = new ClientData[Number];
                for (int i = 0; i < Number; i++)
                {
                    Clients[i].Name = "Client " + i.ToString();
                    Clients[i].ID = i;
                }
            }

            return Clients;
        }

And I create the client for this Web Service:

   LocalService.Service1 service = new LocalService.Service1();
   String data = service.HelloWorld();
   ClientData[] clients = service.GetClientData(3);

I have declared the struct datetype in the Web Service and Web Client:

public struct ClientData
    {
        public String Name;
        public int ID;
    }

Now I get the error in the Cleint:

Error   1   Cannot convert type 'ConsoleApplication1.LocalService.ClientData[]' to 'ConsoleApplication1.ClientData[]'   C:\Users\ademidov\documents\visual studio 2010\Projects\WebService1\ConsoleApplication1\Program.cs  22  36  ConsoleApplication1

How can I fix it ?

Upvotes: 0

Views: 762

Answers (1)

Sidharth Panwar
Sidharth Panwar

Reputation: 4654

Try this:

LocalService.ClientData[] clients = service.GetClientData(3);

What might be happening is that you may have declared ClientData again in your own code but this is not the definition that is being returned by the service. So you need to get the data in the same datatype which was used by the service. Hence we have used the LocalService.ClientData class.

This simply means that we want to use the ClientData class in the LocalService namespace which contains details about the service objects.

Upvotes: 2

Related Questions