Silverlight 3 WCF服务`CommunicationException`服务器返回错误:NotFound [英] Silverlight 3 WCF Service `CommunicationException` Server returned error: NotFound

查看:125
本文介绍了Silverlight 3 WCF服务`CommunicationException`服务器返回错误:NotFound的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Silverlight 3应用程序,其中95%的时间成功地从WCF服务(同一webapp)请求数据并显示它。



这种情况很少发生,通常如果我快速打了很多次,但有时候会发生一个单独的请求。



每隔一段时间,如果我在短时间内要求很多交易,我会得到两个例外之一,它们都出现在 Reference.cs EndMyMethod(System.IAsyncResult result)中的c $ c>文件



有几种方法,任何数量的异常发生。第一个,是我理解的一个 TimeoutException(),这是有道理的,第二个,我完全不能得到的是 CommunicationException()未被用户代码处理:远程服务器返回错误:NotFound。



我把 try..catch 阻止 .MyMethodAsync()和处理程序 MyMethodCompleted 都无效,因为生成的 Reference.cs 文件中出现异常。



任何帮助都是非常感谢。



更新



Reference.cs 由添加服务参考生成

  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];
//这是Exception被抛出的行
base.EndInvoke(TogglePicked,_args,result);
}

致电代码 - chosenIDs 是一个字符串列表, userIDSelecting 是在过程顶部定义的字符串。事件处理程序 mdc_TogglePIckedCompleted 此时为空。

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

foreach(pickID中的字符串ID)
{
mdc.TogglePickedAsync(id,userIDSelecting,mdc);
}

更新2



这是CommunicationException中的InnerException: System.Net.WebException:远程服务器返回错误:NotFound。



不知道这是否有用,因为它没有提供任何额外的细节。正如我所说,这不是每次调用服务方法时都会发生。我也想指出,同一个电话有时会工作,而不是其他电话,我开始认为这个问题是因为IIS没有响应我的服务电话,想法?



更新3



当我的意思是我的意思是我的意思是虔诚的。这只能在用户会话中发生一次,而只能在五十个会话之一中发生。它不是一个无所不在的地方。调用应用程序托管在与WCF服务相同的webite中,所以我不认为clintaccesspolicy.xml是问题,但我可能是错误的。

解决方案

您收到的消息可能是一个红色的鲱鱼: - (



当引发内部WCF服务异常时,它们将始终在Silverlight UI中显示为服务器未找到异常,这是因为HTTP响应的类型为500.我阅读的最好的文章在这方面是来自David Betz - http:// www .netfxharmonics.com / 2008/11 / Understanding-WCF-Services-in-Silverlight-2 (这是针对SL2编写的,但SL3的概念仍然适用,而且他的一些方法是纯粹主义者 - 例如永远不要使用VS的添加服务引用功能 - 您不必遵循他的所有建议;-))



无论如何,回到你的问题,你需要将响应类型转换为200,并解析消息中的异常。这可以使用MessageInspector(在服务和SL应用程序中)完成。





其中一些方法似乎相当艰巨 - 需要一些时间才能理解这一点 - 对于 WCF< - > SL 应用程序而言,这个概念是至关重要的你得到它: - )



自从开始以来,我们已经使用了很多成功一年中,所以如果你需要更多的帮助,请让我知道。


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.

解决方案

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.

这篇关于Silverlight 3 WCF服务`CommunicationException`服务器返回错误:NotFound的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆