1 Replies - 1216 Views - Last Post: 20 February 2013 - 06:51 AM Rate Topic: -----

#1 davers  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 62
  • Joined: 07-April 11

Get data when Web Service returns array

Posted 20 February 2013 - 06:25 AM

Hey Gang,

I'm consuming a web service and all seems to be working well. However, I came across one element that returns an array of objects instead of a single object. I'm not quite grasping what I need to do to get all those objects into an array that I can do something with. Here's the code I'm using:

        public void GetVectorInfoFromCm()
        {
            sms.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["CMUsername"], ConfigurationManager.AppSettings["CMPassword"]);
            submitRequestType request = new submitRequestType();
            request.operation = "display";

            modelChoices choices = new modelChoices();
            ArrayList fields = new ArrayList();

            VectorType myVector = new VectorType();
            myVector.VectorNumber = "";
            myVector.VectorName = "";

            fields.Add(myVector);

            choices.Items = fields.ToArray();
            request.modelFields = choices;
            request.qualifier = "10";

            try
            {
                returnType result = sms.submitRequest(request);
                ExtractAgentLoginIdExtensionsFromCMResult(result);
            }
            catch (Exception e)
            {
                string myExcept = e.Message;
            }

            //GridView2.AutoGenerateColumns = true;
            //GridView2.DataSource = dt;
            //GridView2.DataBind();

            sms.release(sms.sessionID.ToString());
        }


This is connecting to a web service on an AVAYA AES server. To return an object, you have to assign it an empty string...hence the reason for this:

            VectorType myVector = new VectorType();
            myVector.VectorNumber = "";
            myVector.VectorName = "";


since both the VectorNumber and VectorName are single objects, my code works. However, when I try to introduce this:

myVector.VectorStep = "";


I get an error: "Error 1 Cannot implicitly convert type 'string' to 'ConnectToAES.AesSmsService.arrayType[]'"

Can anyone point me in the right direction as to what I need to do?

Thanks for any help!

Dave

Is This A Good Question/Topic? 0
  • +

Replies To: Get data when Web Service returns array

#2 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 362
  • View blog
  • Posts: 1,534
  • Joined: 08-April 09

Re: Get data when Web Service returns array

Posted 20 February 2013 - 06:51 AM

The error is self-explanatory you can't convert string to that object, FYI C# is strongly typed language so you can't expect from compiler to know what you want.

I assume that the VectorStep property is not string.

And another thing
on line 8 ArrayList is relic of the past (.NET 1.1) is encouraged to be replaced with Generics

This post has been edited by Michael26: 20 February 2013 - 06:52 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1