web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Web services issue in ax 2012 r3

(0) ShareShare
ReportReport
Posted on by 568

Hi guys,

I have created a web form using visual studio 2010 and getting the customer id  in the listbox1 by using one button in the form and based on the value selected the customer name will be showed in the second list box2 by using a servicegroup from ax 2012.

Upto this this was working well and good for me.

Now now I have created my own datacontract class and tried to get the custname,Custgroupid,defaultlanguageid  in the form and updated that service group and deployed it again.

In my visual studio also i updated the service reference  and wrote the logic for the third button and looks good.

But i am getting error in the code of the second button.

private void button2_Click(object sender, EventArgs e)

{
    BkCustomAXservice.BKCustomserviceClient servclient = new BkCustomAXservice.BKCustomserviceClient();
    string[] strItem = null;

    int i = 0;

    strItem = new string[listBox1.SelectedItems.Count];

    //Get selected customer ids and prepare a string array

    foreach (Object selecteditem in listBox1.SelectedItems)

    {

        string item  = selecteditem as string;

        strItem[i++] = item;

    }

 

    //Use the string array to get the “Customer Id: Customer Name” Combo data

    string[] custIds = servclient.retrivecustomernames(new BkCustomAXservice.CallContext(), strItem);
    //string[] custIds = servclient.retrivecustomernames(new BkCustomAXservice.CallContext(), strItem);
           

    listBox2.Items.Clear();

    foreach (string custId in custIds)

        listBox2.Items.Add(custId);

}

But i am getting error in the below line,

string[] custIds = servclient.retrivecustomernames(new BkCustomAXservice.CallContext(), strItem);


Error    1    Cannot implicitly convert type 'WindowsFormsApplication1.BkCustomAXservice.BKCustomservicecontract[]' to 'string[]'    c:\users\bharathk\documents\visual studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs    52    24    WindowsFormsApplication1


Please advise.
Regards,
AxTechie 2120

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,904 Most Valuable Professional on at

    The error message is clear. retrivecustomernames() returns an array of BKCustomservicecontract objects, which can't be assigned to a variable of type string[]. Assign the value to BKCustomservicecontract[] variable and then extract values you need (customer name, group ID etc.).

    Also note that your service operation has a misleading name; it doesn't return only customer names anymore.

  • AXTechie2120 Profile Picture
    568 on at

    Thanks for your reply martin,

    Just now i cleared that error but now i am facing another error,

    "Unable to cast object of type 'System.String' to type 'Dynamics.Ax.Application.BKCustomservicecontract'."}

    I have updated my service refernece but i dont know why i get this error.

  • Verified answer
    Martin Dráb Profile Picture
    237,904 Most Valuable Professional on at

    That's the same type of problem. You're trying to assign a string to a variable of type BKCustomservicecontract.

    Pay attention to data type and what the error messages tell you, then you'll be able to figure it out by yourself.

  • AXTechie2120 Profile Picture
    568 on at

    Thank you martin.

    I will check and let you know soon.

  • Verified answer
    AXTechie2120 Profile Picture
    568 on at

    Thank you martin.

    I have solved my problem.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans