7

I'm customizing a shopping cart application in php. In this application, I have to integrate some parts with another C#.net application, so I'm using a webservice in a php shopping cart. In one method of the webservice, some values should pass as an associative array like this:

$proxy = new SoapClient('www.mywebservice.com?wsdl');
$associative_array= array(
    'abc'=> 1,'def'=>0,'ghi'=>1,'jkl'=>0
    );

$proxy->call($sessionId, 'methodname', array('somevalue', $associative_array));

In php its working fine... but the problem is that I'm struggling with C#.net, how can I pass an associative array with C#.net? I'm a php programmer, I think there's no associative array in C#.net and somebody said that C# Dictionary can be used instead of that, but that's not working with the webservice call.

C# code is:

Dictionary<string,string> map=new Dictionary<string,string>();
map.Add("abc","1");
map.Add("def","0");
object st = mgs.call(sessionid, "methodname", new object[] { "somevalue",map  });

Can anybody give some advice???

theduck
  • 2,589
  • 13
  • 17
  • 23
Ullas Prabhakar
  • 3,546
  • 3
  • 28
  • 27
  • 4
    Have you actually tried writing any C# code using dictionaries in order to find out that they don't work with the web service? – BoltClock Mar 14 '12 at 14:33
  • 1
    Apparently SO won't let me post lmgtfy links? At any rate, do a quick search on Google or your favorite search engine for the keywords "C#" "webservice" "dictionary" "serializable" – swasheck Mar 14 '12 at 14:36
  • 3
    @swasheck - no it won't. It's a rude way of telling people they should have searched first. – ChrisF Mar 14 '12 at 14:39
  • 3
    @swasheck This is one of the first results for a Google search of 'C# Associative Array'. Lemme hear ya say Recursion! – Mike Brind Oct 15 '13 at 04:39

3 Answers3

2

I think you want a Dictionary<string, int>. But I could be wrong. You should see what the generated class is used when you call the web service.

To call the web service, right click the References folder of your project. Say Add Service Reference.

Put the WSDL url in there and let it generate the classes for you.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
-1

My guess is that the reason the Dictionary isn't working with the web service call is that Dictionary isn't serializable. Try a SerializableDictionary instead; there's an implementation here:

http://www.dacris.com/blog/2010/07/31/c-serializable-dictionary-a-working-example/

Ken
  • 1