locked
Assigning a List of objects to a web service method RRS feed

  • Question

  • User175729676 posted
    Hi,
    Greetings! And thank you for your time!
    I am working on a web page which creates a list of objects of a class (let's say A).
    The class is a part service that has a method that would accept a list of objects of class A in its contract class.
    In the C# code when I try to assign the list to the class method, I get an error saying, cannon implicitly convert from <A.setObjevts> to A[].set Objects. (Please pardon my pseudo code here as I could not aceess the forum from my workstation and I'm not a regular C# developer).

    If this description is not enough, I will try to get the exact error description.

    Any help is greatly appreciated!

    Regards,
    Abhinay
    Monday, March 25, 2019 4:28 PM

Answers

  • User175729676 posted

    I have found the mistake I was making. Please find the code and error for reference:

      • Web service contract class' list method attribute:
    [DataMemberAttribute("setContractList")
        ,AifCollectionTypeAttribute('return', Types::Class,
                                    classstr(classAContract))
        ,AifCollectionTypeAttribute('_listContract', Types::Class,
                                    classstr(classAContract))]
    
    • C# code
    serviceReference.classAClient clientClassA = new serviceReference.classAClient();
    serviceReference.CallContext callContext = new serviceReference.CallContext();
    callContext.Language = userLangID;
    callContext.Company = CompanyName;
    classAContract contract = clientClassA.addOrUpdateSalesLine(callContext);
    classAContract[] contractsArray = new serviceReference.classAContract[1];
    DataSet myTableDS;
    myTableDS = contract.setmyTable;
    DataTable myTableDT = myTableDS.Tables[0];
    DataRow myTableDR = myTableDT.NewRow();
    myTableDR["myTable.1.CurrencyCode"] = MyCur;
    contractsArray[0].setmyTable = myTableDS;
    List<classAContract> contractList = new List<classAContract>(); //not needed
    contractList.Add(contractsArray[0]); //not needed
    //contract.setContractList = contractList; //this was the mistake 
    contract.setContractList = contractsArray //the correct way of assigning a list of objects
    • And the error message:
    Error	1	Cannot implicitly convert type 'System.Collections.Generic.List<nameSpace.serviceReference.classAContract>' to 'nameSpace.serviceReference.classAContract[]'	..\nameSpace\nameSpace\myPage.aspx.cs
    

    With best regards,

    Abhinay

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 26, 2019 10:14 AM

All replies

  • User303363814 posted

    We will need the exact code and the error message.  An example that anyone can run which shows the problem is the best.

    Monday, March 25, 2019 9:22 PM
  • User175729676 posted

    I have found the mistake I was making. Please find the code and error for reference:

      • Web service contract class' list method attribute:
    [DataMemberAttribute("setContractList")
        ,AifCollectionTypeAttribute('return', Types::Class,
                                    classstr(classAContract))
        ,AifCollectionTypeAttribute('_listContract', Types::Class,
                                    classstr(classAContract))]
    
    • C# code
    serviceReference.classAClient clientClassA = new serviceReference.classAClient();
    serviceReference.CallContext callContext = new serviceReference.CallContext();
    callContext.Language = userLangID;
    callContext.Company = CompanyName;
    classAContract contract = clientClassA.addOrUpdateSalesLine(callContext);
    classAContract[] contractsArray = new serviceReference.classAContract[1];
    DataSet myTableDS;
    myTableDS = contract.setmyTable;
    DataTable myTableDT = myTableDS.Tables[0];
    DataRow myTableDR = myTableDT.NewRow();
    myTableDR["myTable.1.CurrencyCode"] = MyCur;
    contractsArray[0].setmyTable = myTableDS;
    List<classAContract> contractList = new List<classAContract>(); //not needed
    contractList.Add(contractsArray[0]); //not needed
    //contract.setContractList = contractList; //this was the mistake 
    contract.setContractList = contractsArray //the correct way of assigning a list of objects
    • And the error message:
    Error	1	Cannot implicitly convert type 'System.Collections.Generic.List<nameSpace.serviceReference.classAContract>' to 'nameSpace.serviceReference.classAContract[]'	..\nameSpace\nameSpace\myPage.aspx.cs
    

    With best regards,

    Abhinay

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 26, 2019 10:14 AM