I was trying to retrieve data from a WCF web service (.svc) using a WebClient HTTP invocation. The service was signed like this:
[OperationContract]
[WebGet(UriTemplate = "tree/{sessionId}", ResponseFormat = WebMessageFormat.Json)]
public MapData GetTree(string sessionId) {
// ... implementation
}
and returned a complex MapData structure.
The invocation was being performed on Silverlight 3-side, like this:
Uri serviceUri = new Uri(serviceUrl);
But I was getting this error at the very beginning of the client_OpenReadCompleted function:
{System.Net.WebException: The remote server returned an error: NotFound.
at XXX.client_OpenReadCompleted(Object sender, OpenReadCompletedEventArgs e)
at System.Net.WebClient.OnOpenReadCompleted(OpenReadCompletedEventArgs e)
at System.Net.WebClient.OpenReadOperationCompleted(Object arg)}
But the URL was correct and all was installed correctly. So what was wrong?
Solution: This was caused by the impossibility by the server to perform the serialization, because in the data structure there were reference loops. For example:
SampleObject a = new SampleObject();
SampleObject b = new SampleObject();
a.objectReference = b;
b.objectReference = a;
finalDataStructure.add(a);
finalDataStructure.add(b);
After removing such references, the service performed correctly. And since I needed them, I re-added them client-side.