【问题标题】:Calling WCF then use JsonConvert调用 WCF 然后使用 JsonConvert
【发布时间】:2013-12-03 00:49:53
【问题描述】:

如何调用 WCF 并放入以下方法?我在 getSearchCoords() 的 http://kailun92wcf.cloudapp.net/Service1.svc 上有服务。

private void LoadJsonData(object sender, RoutedEventArgs e)
{

    //retrieving the results for the keywords the user input


    searchError.Text = "Loading... Please Wait";
    if (Classes.Global.searched == 1)
    {
        searchVal = new List<string>();
    }

    var service = new Service1Client();
    service.getSearchCoordsAsync(new getSearchCoordsRequest {searchBar.Text.ToString()});
    service.getSearchCoordsCompleted += new EventHandler<MyCloudService.getSearchCoordsCompletedEventArgs>(obj_getSearchCoordsCompleted);



 //        string data = @"{
    //
    //                         ""PageCount"" : ""1"",
    //                         ""SearchResults"": [
    //                            {
    //                                ""SEARCHVAL"": ""ORCHARD22"",
    //                                ""CATEGORY"": ""Building"",
    //                                ""X"": ""29483.4267"",
    //                                ""Y"": ""31269.938""
    //                            },
    //                            {
    //                                ""SEARCHVAL"": ""ORCHARDBELAIR"",
    //                                ""CATEGORY"": ""Building"",
    //                                ""X"": ""27071.2616"",
    //                                ""Y"": ""31629.2465""
    //                            }
    //                        ]
    //                    }";

    var pagedResults = JsonConvert.DeserializeObject<TestMap.Classes.Global.ResultSetPager<TestMap.Classes.Global.Place>>(data);

        //or lstPlaces
    Results.ItemsSource = pagedResults.SearchResults;
}

需要将 svc 中的 json 数据放入结果中以显示在我的 windows phone 上。我该怎么做?

【问题讨论】:

标签: c# json wcf


【解决方案1】:

现在,您的服务正在为任何搜索参数返回一个“错误”字符串。

 private void LoadJsonData(object sender, RoutedEventArgs e)
    {
        var service = new Service1Client();
        service.getSearchCoordsAsync(new getSearchCoordsRequest(searchBar.Text));
        service.getSearchCoordsCompleted += new EventHandler<getSearchCoordsCompletedEventArgs>(obj_getSearchCoordsCompleted);
    }

    public void obj_getSearchCoordsCompleted(object sender, getSearchCoordsCompletedEventArgs e)
    {
        var response = e.Result.getSearchCoordsResult;
        var pagedResults = JsonConvert.DeserializeObject<ResultSetPager<Place>>(response);
        lstPlaces.ItemsSource = pagedResults.SearchResults;
    }

【讨论】:

  • 我遇到了这个错误 错误 1 ​​找不到类型或命名空间名称“Place”(您是否缺少 using 指令或程序集引用?)
  • 还有这个错误 2 找不到类型或命名空间名称“ResultSetPager”(您是否缺少 using 指令或程序集引用?)
  • 如果我将代码更改为此 我会在每个位置名称上方的列表视图中显示类似 testmap.classes.global 的奇怪结果.
  • 你的 XAML 看起来像什么?您很可能没有引用 String / Int 类型,而是标记中的“Place”之类的对象
  • 非常感谢您是对的,xaml 中有一个按钮。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-16
相关资源
最近更新 更多