在c#中使用wcf服务时获取null值

时间:2013-11-23 05:10:53

标签: c# asp.net

使用c#在asp.net中使用wcf服务时获取空值。我正在使用此代码。 请给我正确的解决方案来做这项活动。

protected void rtrFile()
    {
       string newvar="";
        string url = "http://vinipost.com/Services/Mobile_Application/wcfService.svc/getGroup?usrId=100";
        using (StreamReader streamReader = new StreamReader(WebRequest.Create(url).GetResponse().GetResponseStream()))
             newvar= streamReader.ReadToEnd();

        vpData fbdata = new JavaScriptSerializer().Deserialize<vpData>(newvar);

        GridView1.DataSource = fbdata.Data;
        GridView1.DataBind();
    }
  public class vpData
    {       
        public string getFriendsResult { get; set; }
        public List<vpkUser> Data { get; set; }
    }

    public class vpkUser
    {
        public string code { get; set; }
        public string name { get; set; }
    }

1 个答案:

答案 0 :(得分:0)

您的modelJSON不匹配:

试试这个:

protected void rtrFile()
    {
        string newvar = "";
        string url = "http://vinipost.com/Services/Mobile_Application/wcfService.svc/getGroup?usrId=100";
        using (StreamReader streamReader = new StreamReader(WebRequest.Create(url).GetResponse().GetResponseStream()))
        newvar = streamReader.ReadToEnd();


        vpData fbdata = new JavaScriptSerializer().Deserialize<vpData>(newvar);

        GridView1.DataSource = fbdata.getGroupResult;
        GridView1.DataBind();
    }
    public class vpData
    {     
        public List<vpkUser> getGroupResult { get; set; }
    }

    public class vpkUser
    {
        public string code { get; set; }
        public string name { get; set; }
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        rtrFile();
    }