Json Web服务返回null响应

时间:2014-06-04 14:50:35

标签: .net json

我创建了Web服务,它从其他Web服务获取数据并返回字符串响应,但是当我第一次调用它时返回null,但第二次它完美地工作。 这是我的代码:

[WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string getStandings(string comp_id)
    {
        WebClient w = new WebClient();
        w.DownloadStringCompleted += StandingsDownloadCompleted;
        w.DownloadStringAsync(new Uri("http://football-api.com/api/?Action=standings&APIKey=" + apikey + "&comp_id=" + comp_id));
        return StandingsString;
    }

    public static string StandingsString { get; set; }

    public void StandingsDownloadCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        StandingsString = e.Result;
    }

有什么问题?

0 个答案:

没有答案
相关问题