1

I have a web-service method that returns a

List<KeyValuePair<string,double>>

However when I use use that method in a service reference, the object it returns is

List<KeyValuePairOfStringDouble>

I cannot figure out how to use this.

colobusgem
  • 473
  • 1
  • 4
  • 18
  • What do you mean you cannot figure it out? What is the problem? – nvoigt Aug 18 '15 at 09:17
  • how do I use it? for example I want to update a chart with the data returned from the service. however the chart.add method requires a KeyValuePair it wont take KeyValuePairOfStringDouble. – colobusgem Aug 18 '15 at 09:20
  • 1
    Did you create a type called `KeyValuePairOfStringDouble`? – Yuval Itzchakov Aug 18 '15 at 09:20
  • Is it your webservice? Would you be able to simply deliver a contract assembly so you don't have to rely on the WSDL getting things a 100% like you want it? – nvoigt Aug 18 '15 at 09:22
  • yes it is my service, a contract assembly is not something I have come across before. – colobusgem Aug 18 '15 at 09:26

1 Answers1

1

Your service reference is trying to make the best out of the WSDL it gets. But your service and your application have been playing games with each other. They were never allowed to directly talk. So you are now stuck with something that looks like what you need and is called like what you need, but it is not exactly what you need.

Simple solution is to build a new list that is what you syntactically need:

List<KeyValuePair<string,double>> yourlist = serviceResult.Select(kvp => new KeyValuePair<string, double>(kvp.Item1, kvp.Item2)).ToList();

For a better solution in the future you should let both ends of your service communication know what the other end is up to syntactically. This is called a contract assembly.

This thread on StackOverflow and the links that it contains might be a good start if you want to build one for your service.

Community
  • 1
  • 1
nvoigt
  • 75,013
  • 26
  • 93
  • 142