views:

23

answers:

1

How to pass a dictionary in a method in WCf ...
I'm doing this

public void SendData(Dictionary<string, string > data)
{
    foreach (KeyValuePair<string, string> item in data)
    {
        Console.WriteLine("{0} : {1}", item.Key, item.Value);
    }
}

When I access it as 192.X.X.X//Akhil/service.svc/SendData?data={}
here What/How should I pass arguments in data...some example please.

A: 

Generate your proxy (Say, "TestProxy") then do:

TestProxy.YourServiceClient client = new TestProxy.YourServiceClient();

Dictionary<string, string> testDict = new Dictionary<string, string>();

testDict.Add("test", "test1");

client.SendData(testDict);

WCF will serialize your Dictionary with no problem. The problem here is that you are trying to access your WCF service as if you exposed it as a REST Service through an HTTP Get request. I'm pretty sure based on your question, you aren't exposing this as a REST service. If you want to be able to do Get Requests, then google .Net WCF REST.

*Note: you might also want to look into the Request/Response SOA pattern, it's going to save a bunch of trouble down the road.

Update:

Here are some links that might point you in the right direction, you'll probably want to expose your WCF service as a JSON endpoint.

JSON / REST Link

Search Dictionary in this LINK to get some details on alternatives and gotchas in WCF JSON.

Hope these help. I have never done an Iphone app so I don't have any source code to give you.

CkH
Hi CKH Thanks for help... I want to send post data from Iphone.I have to send a dictionary(K-V pairs) with 8 k-v pairs.I have to receive this dictionary in WCF ...please just help me how will handle it.i m really sorry if this is something stupid...please help me by some code if possible.
No, not stupid at all. I've updated my post above with some links to help you out.
CkH