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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:46:09+00:00 2026-05-25T00:46:09+00:00

I have a WebMethod with the following signature: [WebMethod] public void SaveRoute(int id, Coordinates[]

  • 0

I have a WebMethod with the following signature:

[WebMethod]
    public void SaveRoute(int id, Coordinates[] coordinates)
    {
    }

Where Coordinates is:

/// <summary>
/// A position on the globe
/// </summary>
public class Coordinates
{
    public decimal Longitude { get; protected set; }
    public decimal Latitude { get; protected set; }

    public Coordinates(decimal latitude, decimal longitude)
    {
        this.Longitude = longitude;
        this.Latitude = latitude;
    }
}

I want to call this from a jQuery ajax method like this one:

$.ajax({
                    type: "POST",
                    url: "Routes.asmx/SaveRoute",
                    cache: false,
                    contentType: "application/json; charset=utf-8",
                    data: '{"id":1, ,"coordinates": "Longitude":123,"Latitude":456}',
                    dataType: "json",
                    success: handleHtml,
                    error: ajaxFailed
                });

What would I have to supply in the data property for a correct deserialisation?

I have now solved it:

Thanks for all the help, I eventually managed to get what I wanted with the following code:

var coords = new Array();
            for (ckey in flightPlanCoordinates) {
                var thisWaypoint = { "Longitude": flightPlanCoordinates[ckey].lng(), "Latitude": flightPlanCoordinates[ckey].lat() };
                coords.push(thisWaypoint);
            }
            var data = { "id": 1, "coordinates": coords };
            if (flightPlanCoordinates) {

                $.ajax({
                    type: "POST",
                    url: "Routes.asmx/SaveRoute",
                    cache: false,
                    contentType: "application/json; charset=utf-8",
                    data: JSON.stringify(data),
                    dataType: "json",
                    success: handleHtml,
                    error: ajaxFailed
                });
            }

I reverse engineered the JSON by sending some down with another method:

[WebMethod]
    public Coordinates[] Get()
    {
        return new Coordinates[]
        {
            new Coordinates(123, 456),
            new Coordinates(789, 741)
        };
    }

It is also important that you have a public parameterless constructor in your class and your property’s setters are public:

/// <summary>
/// A position on the globe
/// </summary>
public class Coordinates
{
    public decimal Longitude { get; set; }
    public decimal Latitude { get; set; }

    public Coordinates()
    {
    }

    public Coordinates(decimal latitude, decimal longitude)
    {
        this.Longitude = longitude;
        this.Latitude = latitude;
    }
}
  • 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-25T00:46:10+00:00Added an answer on May 25, 2026 at 12:46 am

    I recommend using JSON.stringify to build your “JSON” strings.
    With JSON.stringify you can convert a array of coordinates to a JSON string representation.
    Example:

    var id = 2;
    var coords = new Array();
    
    coords[0] = { Longitude: 40.0, Latitude: 76.0 };
    coords[1] = { Longitude: 42.0, Latitude: 77.0 };
    
    $.ajax({
        type: "POST",
        url: "Routes.asmx/SaveRoute",
        cache: false,
        contentType: "application/json; charset=utf-8",
        data: '{ "id":' + JSON.stringify(id) + ', "coordinates":' + JSON.stringify(coords) + '}',
        dataType: "json",
        success: handleHtml,
        error: ajaxFailed });
    

    If you place your SaveRoute web method on a aspx website you can use ScriptManager to generate
    page methods and script types (see MSDN documentation for GenerateScriptTypeAttribute).

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

Sidebar

Related Questions

I have an ASP.NET 2.0 web method with the following signature: [WebMethod] public QueryResult[]
I have an ASP.NET PageMethod with the following signature: <WebMethod()> _ Public Shared Function
I have the following web service: [ScriptService] public class Handler : WebService { [WebMethod]
I have the following code: [WebMethod] [SoapHeader(_webServiceAuth)] public User GetUser(string username) { try {
Suppose I have the following methods declared in my web service: @WebMethod() public Long
I have the following that I'm using in every page: public partial class Pages_MyPage
I have a simple web service operation like this one: [WebMethod] public string HelloWorld()
If I have a web service method, e.g. [WebMethod] [XmlInclude(typeof(SportsCar)), XmlInclude(typeof(FamilyCar))] public Car[] GetCars()
I have the following jquery code to call a webmethod in an aspx page
I have the following class in Class Library: Artist , which is a POCO

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.