1

I'm using JavaScript to access a ScriptService method called GetPerson(). The problem is that it is returning a fairly empty JSON string instead of an actual object string. The same happens when I return a new DateTime object so the class is out of question I hope.

This is returned:

{"d":{"__type":"Person"}}

this is my WebService.cs:

using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Web.Script.Services;

/// <summary>
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class WebService : System.Web.Services.WebService
{
    public WebService () {
        //InitializeComponent(); 
    }

    [WebMethod]
    [ScriptMethod(ResponseFormat=ResponseFormat.Json)]
    public Person GetPerson(string whatever)
    {
        Person x = new Person("gaga",DateTime.Now,null);
        return x;

    }
}
Brian Johnson
  • 1,629
  • 5
  • 21
  • 26

1 Answers1

3

And so it turns out that this was indeed a problem with my class file. Works a lot better with public properties.

public string name { get; set; }

2 hours of debugging is nothing vs. Stackoverflow induced inspiration. doh.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Brian Johnson
  • 1,629
  • 5
  • 21
  • 26