NotFound exception, but service URI is OK


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);

WebClient client = new WebClient();
client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
client.OpenReadAsync(serviceUri);

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.

Information and Links

Join the fray by commenting, tracking what others have to say, or linking to it from your blog.


Other Posts

Write a Comment

Take a moment to comment and tell us what you think. Some basic HTML is allowed for formatting.

Reader Comments

Be the first to leave a comment!