views:

1253

answers:

5

I have a Silverlight 3 application, which 95% of the time is successfully requesting data from a WCF Service (in the same webapp) and displaying it.

This happens infrequently, usually if I hit the service a bunch of times quickly, but sometimes it'll happen on a single lone request.

Every once in a while, if I request a lot of transactions in a short period, I get one of two exceptions, they both occure in the Reference.cs file in the EndMyMethod(System.IAsyncResult result).

There are a few methods, and the exceptions occure on any number of them. The first one, is a TimeoutException() which I understand and it makes sense, the second one, which I totally don't get is the "CommunicationException() was unhandled by user code: The remote server returned an error: NotFound."

I've put try..catch blocks both arround the .MyMethodAsync() and in the handler for MyMethodCompleted both to no avail, as the exception occurs in the generated Reference.cs file.

Any help is greatly appreciated.

update

Reference.cs -- generated by "Add Service Reference"

public System.IAsyncResult BeginTogglePicked(string ID, string toggle, System.AsyncCallback callback, object asyncState) 
{
   object[] _args = new object[2];
   _args[0] = ID;
   _args[1] = toggle;
   System.IAsyncResult _result = base.BeginInvoke("TogglePicked", _args, callback, asyncState);
   return _result;
}

public void EndTogglePicked(System.IAsyncResult result) 
{
   object[] _args = new object[0];
   // This is the line where the Exception is Thrown
   base.EndInvoke("TogglePicked", _args, result);
}

Calling Code -- pickedIDs is a list of Strings, and userIDSelecting is a string defined at the top of the procedure. The Event Handler mdc_TogglePIckedCompleted is empty at the moment.

MapDataClient mdc = new MyDataClient();
mdc.TogglePickedCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(mdc_TogglePickedCompleted);

foreach (string id in pickedIDs)
{
    mdc.TogglePickedAsync(id, userIDSelecting, mdc);
}

Update 2

This is the "InnerException" from the CommunicationException: System.Net.WebException: The remote server returned an error: NotFound.

Not sure if this is any more helpful, since it doesn't give any extra details. As I said, this happens intermitently not every time I call a service method. I'd also like to point out that the same call will work sometimes and not others, I'm starting to think this issue is because IIS is failing to respond to my service calls, thoughts?

Update 3

When I mean intermiently, I mean truel intrmitent. This may only occur a single time in a user's session, and it may only occur on one of fifty sessions. Its not an all-or-nothing sitation. The calling application is hosted within the same "webite" as the WCF Service, so I don't think a clintaccesspolicy.xml is the issue, but I could be wrong.

A: 

Is your service returning exception details to the client? By default it does not. You could add the following attribute to your service class.

[ServiceBehavior(IncludeExceptionDetailInFaults=true)]
public class MyService ...

You may find you're getting some kind of server-side exception that is not visible to the client.

Josh Einstein
I don't have that code, but in the web.config file, I have Exception Details being returned. I'll have to check what the "InnerException" is, if it is anything.
Nate Bross
Updated question with contents of InnerException.
Nate Bross
A: 

Make sure you have a clientaccesspolicy.xml file. Otherwise you may get that error cause the policy file cannot be found.

Bill Moore
A: 

I had exactly the same problem as you - absolute nightmare, it would work sometimes and then just stop.

After reading your post earlier I kept looking for clientaccesspolicy info and found this (can't remember where), but I use it and it now works fine!

Hope the same is good for you :) My file was missing the extra detail on the allow-from section.

<?xml version="1.0" encoding="utf-8" ?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="*">
        <domain uri="http://*" />
        <domain uri="https://*" />

      </allow-from>


      <grant-to>
        <resource include-subpaths="true" path="/"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>
Mike Talbot
Update question, I don't think its a client access policy, since the SL app and the WCF are in the same asp.net web app. Could this still be the issue?
Nate Bross
+1  A: 

The message that you are getting are probably a red herring :-(

When internal WCF service exceptions are thrown, these will ALWAYS manifest themselves as Server Not Found exceptions in the Silverlight UI. This is because the HTTP response is of type 500. The best article I read on this was from David Betz - http://www.netfxharmonics.com/2008/11/Understanding-WCF-Services-in-Silverlight-2 (this was written for SL2, but the concepts still holds for SL3. Also, some of his approaches are for purists - e.g. "NEVER" using the Add Service Reference features from VS - you don't have to follow all his advice ;-) )

Anyway, back to your question, you need to convert the response type to 200 and parse the exception in the message. This can be done using a MessageInspector (in the service and SL app).

Some of these approaches can seem quite daunting - take some time to understand this - the concept is crucial for WCF <--> SL applications, and it makes sense once you get it :-)

We've used this with a lot of success since the start of the year, so if you need anymore help with this just let me know.

Best,
Mark

Mark Cooper
A: 

Can I recommend always, always having Fiddler running when you are working with Silverlight and WCF?

elsharpo