Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have created a web service interface with method like,

[OperationContract]

       
        string Log(string COMMENTS, string product, Dictionary<string, List<string>> analysisComp);


The issue here is if i try to consume this webservice and try to pass the values to Dictionary <string , List<string>> variable it gives me the following error:

cannot convert from 'System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>>' to ArrayOfKeyValueOfstringArrayOfstringty7Ep6D1KeyValueOfstringArrayOfstringty7Ep6D1[]	


CAn you please advise if i cant use this datatype of Dictionary in my webservice method what would be the best alternate for it..

Thanks,.

What I have tried:

Create Web service but datatype of Dictionary is not accepting.
Posted
Updated 3-Oct-18 3:05am
Comments
Alek Massey 27-Sep-18 11:43am    
Can you show the line of code (in context) that is giving the error?
Mohammad Azeem 2-Oct-18 3:24am    
Hi Alek,

Let me share more details:

I created two C# solutions 1 from where i am hosting the Web service and the other one is consuming it, for the first solution i write the code to accept the parameters as follows:

[OperationContract]


string LogSS(string priority, string Reason, string COMMENTS, Dictionary<string, List<string>> analysisComp);
mp);
While at consumption side, i added a web reference with the succeeding mapping:


Then i clicked Add web reference button to add the reference to the hosted service.

The code i write to access the webservice is as follows:

string priority = "3";
string Reason = "Reason";
string COMMENTS = "COMMENTS";
Dictionary<string, List<string>> analysisComp = new Dictionary<string, List<string>>()
{
["CHEM"] = new List<string> { "Water", "Liquid" },
["Basse"] = new List<string> { "Acid", "Calcium", "Magnesium" }

};
string ID = consume.LogSS(priority, Reason, COMMENTS, analysisComp);
Console.WriteLine(ID, true);

Console.ReadLine();
While executing it gives the following error:

Error CS1503 Argument 13: cannot convert from 'System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>>' to 'WebSeriveConsumeWCF.Service.ArrayOfKeyValueOfstringArrayOfstringty7Ep6D1KeyValueOfstringArrayOfstringty7Ep6D1[]' WebSeriveConsumeWCF
Please Advise Thanks.

Note: without Dictionary <string>... parameter the web service is working absolutely fine.

1 solution

Try using this to initialize tyour dictionary.
C#
Dictionary<string, List<string>> analysisComp = new Dictionary<string, List<string>>();
analysisComp.Add("CHEM", new List<string>() { "Water", "Liquid" });
analysisComp.Add("Basse", new List<string>() { "Acid", "Calcium", "Magnesium" });
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900