Returning a struct array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • programmerboy
    New Member
    • Jul 2007
    • 84

    Returning a struct array

    Hi All,
    I have a webservice that returns an array of struct based on different parameters. My strcut is declared like that
    Code:
    //Struct to be sent
    public struct UserData
    {
        public string userID , fName , lName , IMO , status, businessAddress, city, state, zip, telephoneNumber, mail;
    }
    I have a method that returns an array of struct, based on IMO. If I test this webservice using .NET environment, it works fine. But when I try to call this webservice in aspx page it gives me an error of
    Code:
    Cannot convert type 'User_Interfaces.getSpecificUsers.UserData[]' to 'ADAM.AddTwoNumbers.UserData[]'
    Although I have same struct defined in my aspx page. This is how I am trying to get array of struct in ASPX page.

    Code:
    UserData[] returnedUsers = (UserData[])getUsers.getUsersByIMO(server,port,DN,"IMO*");
    I am new to passing structs, can any one please help me in solving this.
    Thanks in advance.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    The compiler is getting confused with ambiguous component names.
    There are multiple objects with the UserData name, and it is unsure which one you want to use.
    If you fully qualify your component with the namespace you should be fine.
    You couls also try changing the name of your object to a little bit more unique name so as to avoid conflicts.

    Comment

    • programmerboy
      New Member
      • Jul 2007
      • 84

      #3
      Originally posted by Plater
      The compiler is getting confused with ambiguous component names.
      There are multiple objects with the UserData name, and it is unsure which one you want to use.
      If you fully qualify your component with the namespace you should be fine.
      You couls also try changing the name of your object to a little bit more unique name so as to avoid conflicts.
      Hi Plater,
      I understood half of what you explained (not your fault). Could you please exactly tell me what you meant by ambiguous names, and where I am using it. Your help will be greatly appreciated.

      Comment

      • programmerboy
        New Member
        • Jul 2007
        • 84

        #4
        Originally posted by programmerboy
        Hi Plater,
        I understood half of what you explained (not your fault). Could you please exactly tell me what you meant by ambiguous names, and where I am using it. Your help will be greatly appreciated.
        Ok, Now I have change the names per your suggestion
        Code:
        //Struct to be sent
        public struct UserDataSent
        {
            public string userID , fName , lName , IMO , status, businessAddress, city, state, zip, telephoneNumber, mail;
        }
        and in the ASPX page I have declared it as following.

        Code:
        //Struct to be received
        public struct UserDataReceived
        {
            public string userID , fName , lName , IMO , status, businessAddress, city, state, zip, telephoneNumber, mail;
        }
        But still I get following error

        Code:
        Cannot convert type 'User_Interfaces.getSpecificUsers.UserDataSent[]' to 'ADAM.AddTwoNumbers.UserDataReceived[]'
        This is how I assigning struct array sent.

        Code:
        UserDataReceived[] returnedUsers = (UserDataReceived[])getUsers.getUsersByIMO(server,port,DN,"IMO*");

        By the way I have also changed above code to following, but still it didn't work.

        Code:
        UserDataReceived[] returnedUsers = (UserDataSent[])getUsers.getUsersByIMO(server,port,DN,"IMO*");

        What I am doing wrong then

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Between your code and included libraries, there are duplicate names (ie: UserData)
          Say I create a namespace called "Plater" with a class called "Car" and I have a namesapce called "Other" with a class called "Car".
          If I include both "Plater" and "Other" in my project and then do:
          Car acar= new Car();
          The compiler will go "Which Car do you mean? Plater.Car or Other.Car ?"
          You are in a similar situtation. Your function is declared to return an array of UserData from a particular namespace while the compiler thinks your weak-qualified class name (Using Car instead of Plater.Car) is from a different namespace and is complaining that you aren't converting properly.

          Comment

          • programmerboy
            New Member
            • Jul 2007
            • 84

            #6
            Originally posted by Plater
            Between your code and included libraries, there are duplicate names (ie: UserData)
            Say I create a namespace called "Plater" with a class called "Car" and I have a namesapce called "Other" with a class called "Car".
            If I include both "Plater" and "Other" in my project and then do:
            Car acar= new Car();
            The compiler will go "Which Car do you mean? Plater.Car or Other.Car ?"
            You are in a similar situtation. Your function is declared to return an array of UserData from a particular namespace while the compiler thinks your weak-qualified class name (Using Car instead of Plater.Car) is from a different namespace and is complaining that you aren't converting properly.
            Thankyou Plater (Is this your name by the way?),
            Actually what I have been doing wrong is to creating a struct in my ASPX page. My initial understanding was that for receiving structs you have to create exactly the same struct in your receiving class and declare a variable of struct that you just created in your receiving class(ASPX page). And then call the method which will return array of struct and then cast it to your declared struct.

            Sounds stupid, but its good that I realized sooner than later.

            Thanks again for your help Plater.

            Comment

            Working...