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;

    }
}

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.