Following this tutorial: I have created a WP8 Mobile Application and trying to call my WCF web service. When calling the WCF service in the browser, I can see the JSON returned with no problems at all. However, when I call the WCF service in my mobile application, I don't get anything back. I have no clue where I am going wrong.
This is the code that calls the WCF:
string ServiceUri = "urlgoeshere";
WebClient proxy = new WebClient();
proxy.DownloadStringCompleted += new DownloadStringCompletedEventHandler(proxy_DownloadStringCompleted);
proxy.DownloadStringAsync(new Uri(ServiceUri));
And the event handler:
Stream stream = new MemoryStream(Encoding.Unicode.GetBytes(e.Result));
DataContractJsonSerializer obj = new DataContractJsonSerializer(typeof(List<SightingType>));
var result = obj.ReadObject(stream) as List<SightingType>;
What am I doing wrong? I've obviously changed the ServiceUri to "urlgoeshere" but rest assured, the actual URL works perfectly, 100% A-OK when I run it in my browser. When running it in this mobile app however, it doesn't work. Can anyone see the obvious problem?
Update
1) If I do:var result = obj.ReadObject(stream);
, and if I step into stream
, I can see a:
ReadTimeout = 'stream.ReadTimeout' threw an exception of type 'System.InvalidOperationException'
2) Also, I have two WCF Methods which I can run. The one I am having problems with works on the browser but not on the mobile phone. The other one works perfectly fine on both. The different between the two is that there is no parameter at the end on one of them. So the first one is http://......?brandId=brands/1 and the other one doesn't have any parameters: http://...... <-- this one works. Could it be that it's not encoding the forward slash?