2

Hi I have just started learning WCF and I have encountered an error I do not understand.

This method returns an error saying:

The best overloaded method match for "PersonKlient.ServiceReference1.PersonTjenesteGrensesnitt.searchAge(int)' has some invalid arguments"

Here is the code

   private void button3_Click(object sender, EventArgs e)
    {
        var personer = _tjeneste.searchAge(textBox2.Text);

        listBox1.Items.Clear();
        foreach (var person in personer)
        {
            listBox1.Items.Add(person.Fornavn + " " + person.EtterNavn);
        }
    }

However the method called is supposed to take a String argument. Not an int.

        public List<Person> searchAge(String age)
    {
        List<Person> result = new List<Person>();
        int numAge = Convert.ToInt32(age);

        foreach (Person person in personer)
        {
            if (person.Alder == numAge)
                result.Add(person);
        }
        return result;
    }

Why am I getting this error?

1 Answer 1

4

Have you changed the service (to change the parameter from int to string) but not regenerated the proxy code? That would certainly explain it - regenerate the service reference, and all should be well.

Sign up to request clarification or add additional context in comments.

2 Comments

I am also pretty new to Visual Studio so could you tell me how I can regenerate the reference?
@SvennK Right-click the reference and select 'Update Web/Service Reference' from the context menu.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.