Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8167743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:17:43+00:00 2026-06-06T20:17:43+00:00

I need to pass a simple Javascript array to my wcf ajax webservice: var

  • 0

I need to pass a simple Javascript array to my wcf ajax webservice:

var array = new Array();
array["ParamA"] = "xyz";
array["12344"] = "9";
myNamespace.DoSomething(array);

This this my WCF method:

[OperationContract]
[WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public void DoSomething(object values)

“values” is an empty array when it is called from javascript with my values.
What is the best approach to pass a simple list of KeyValuePairs to my webservice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T20:17:45+00:00Added an answer on June 6, 2026 at 8:17 pm

    I was able to find the solution myself:

    [OperationContract]
    [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    public void DoSomething(Dictionary<string, object> values)
    

    must be called in javascript like this:

    var params = [{ “Key”: “A”, “Value”: 5}, { “Key”: “B”, “Value”: “Test}]

    $.ajax({
        type: "POST",
        contentType: "application/json",
        dataType: "json",
        data: '{"values":' + JSON.stringify(params) + '}',
        ...
    

    This can of course be simplified:

    var parameters = [{ "A": 5}, { "B": "Test"}];
    
    var dictionary = new Array();
    for (var i in parameters) {
       var key = Object.keys(args[i])[0];
       var value = args[i][key];
       dictionary.push({ "Key": key, "Value": value });
    } 
    
    $.ajax({
        type: "POST",
        contentType: "application/json",
        dataType: "json",
        data: '{"values":' + JSON.stringify(dictionary) + '}',
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple javascript function that takes two variables. I need to pass
I want to create a simple bookmarklet to pass some information from javascript to
I'm new to AJAX/javascript, and I'm not sure what the best approach is for
I don't need anything fancy or complex, I'm just trying to pass a simple
In javascript I need to know if array contains value. Values are objects and
I have posted my class below and with sample data. I need to pass
I need to pass an extra parameter :mobilejs => true from jQuery to a
I need to pass argument to JNLP dynamically for which I tried using a
I need to pass Cursor object to another activity, what is the best way
I need to pass a variable which is captured from client side via jquery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.