0

我正在调用 WCF 服务,但结果返回为空。但是,当我在浏览器中运行该服务时,我可以看到返回的 JSON 没有问题。

代码:

var webClient = new WebClient();
var uri = new Uri("http://myWebsite.com/MobileService.svc/MyMethod?brandId=brands/1");
webClient.OpenReadCompleted += webClient_OpenReadCompleted;
webClient.OpenReadAsync(uri);

在 webClient_OpenreadCompleted 事件中:

ser = new DataContractJsonSerializer(typeof(ObservableCollection<SightingType>));
List<SightingType> sightingTypes = ser.ReadObject(e.Result) as List<SightingType>;

但是由于某种原因,sightingTypes 结果为空。此外,当我在调试时将鼠标悬停在 e.Result 上时,我可以看到这个错误:

ReadTimeout = 'e.Result.ReadTimeout' 引发了“System.InvalidOperationException”类型的异常

有谁知道为什么我无法取回数据?

4

0 回答 0