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 6122255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:52:39+00:00 2026-05-23T15:52:39+00:00

Suppose I write the following C# code to define a web method: public class

  • 0

Suppose I write the following C# code to define a web method:

public class Thing
{
    public string X {get;set}
    public string Y {get;set}
}

[WebMethod]
public static void myFunction(Thing thing) { }

I’ve discovered that I can invoke the function using the jQuery JavaScript that looks like this:

var myData = { X: "hello", Y: "world" };
var jsonData = JSON.stringify(myData);
jQuery.ajax({ data: jsonData, ...

When myFunction is thus invoked, thing.X is set to “hello” and thing.Y is set to “world”. What exactly does the .net framework do to set the value of thing? Does it invoke a constructor?

  • 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-05-23T15:52:39+00:00Added an answer on May 23, 2026 at 3:52 pm

    Just like you can create Thing like so

    Thing x = new Thing { X = "hello", Y = "world" }
    

    So no it does not call the constructor to answer your question.

    Ok, more detail…

    It takes the JSON and deserializes it. It fills the properties from you JSON object. For example, if you had the following in JSON:

    {"notRelated":0, "test": "string"}
    

    The serializer would not find X or Y for thing and set them to the default value for that data type.

    Let’s say you want to go deeper. You can custom serialize and deserialize your objects:

    [Serializable]
    public class MyObject : ISerializable 
    {
      public int n1;
      public int n2;
      public String str;
    
      public MyObject()
      {
      }
    
      protected MyObject(SerializationInfo info, StreamingContext context)
      {
        n1 = info.GetInt32("i");
        n2 = info.GetInt32("j");
        str = info.GetString("k");
      }
    [SecurityPermissionAttribute(SecurityAction.Demand,SerializationFormatter=true)]
      public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
      {
        info.AddValue("i", n1);
        info.AddValue("j", n2);
        info.AddValue("k", str);
      }
    }
    

    So you can see, it’s fishing for parameters in your case, X and Y.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I write the following code: public ref class Data { public: Data() {
Suppose I write a library with the following: public class Bar { /* ...
Suppose we have the following method (it is in c code): const char *bitap_search(const
suppose I have the following class: class MyInteger { private: int n_; public: MyInteger(int
Given the following code (it's supposed to write helloworld in a helloworld file, and
Suppose someone (other than me) writes the following code and compiles it into an
Suppose you have the following string: white sand, tall waves, warm sun It's easy
Suppose, I write class A { }; The compiler should provide (as and when
hi i have write following code which prints elements in sorted order only one
Suppose I have the following two data structures: std::vector<int> all_items; std::set<int> bad_items; The all_items

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.