帮助调试 WCF [英] Help debugging WCF

查看:33
本文介绍了帮助调试 WCF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 WCF 编程的新手,我发现学习过程相当令人沮丧.据我所知,WCF(和 WPF,就此而言)默认会隐藏错误.到目前为止,我遇到了以下问题,并且 Visual Studio 或运行时的指示基本上为零,表明存在任何错误(除了我的应用程序无法正常工作):

I am new to WCF programming and am finding the learning process rather frustrating. As far as I can tell, WCF (and WPF, for that matter) will hide errors from you by default. So far I have experienced the following problems and had essentially zero indication from Visual Studio or the runtime that there was anything wrong (other than my application just not working):

  • 服务引用不是最新的(为什么 VS 不自动执行此操作?);
  • 无法序列化服务方法中的类型;
  • 该服务试图传递的数据超出默认值.

大概有一些简单的方法可以让我(开发人员)看到这些问题.如果有人能告诉我它是什么,我将不胜感激(数小时的谷歌搜索没有提供有效的答案)!

Presumably there is some simple way of making these problems visible to me, the developer. If anyone can tell me what it is, I would be very grateful (hours of googling have not provided a working answer)!

如果有人知道为什么 WCF 和 WPF 的默认行为是悄悄地隐藏这样的错误,我也很感激.至少可以说,这似乎很奇怪.

I would also appreciate an explanation, if anyone knows, why the default behaviour for WCF and WPF is to quietly hide errors like this. It seems bizarre, to say the least.

推荐答案

我猜你误解了 Web 服务的基本概念.WCF 是用于构建 Web 服务的 API.与 RPC 相比,Web 服务应该独立使用.这意味着您可以在不知道将使用它的应用程序的情况下创建 Web 服务(您可以将 Web 服务公开给 Internet 或业务合作伙伴).这与 RPC 有很大不同,RPC 大部分时间将客户端和服务构建在一起.默认情况下,基于基本安全实践,服务异常不会发送到客户端.您不想向未知客户公开内部信息.

I guess you have missunderstand elementary ideas of Web services. WCF is API for building web services. Web services in contrast to RPC are supposed to be used independently. It means that you can create web service without knowing the application which will used it (you can expose web service to Internet or to business partner). It is a big difference to RPC where client and service are most of the time built together. Based on elementary security practices service exceptions are not send to client by default. You don't want to expose internal information to your unknown clients.

回答您的问题:

服务参考不是最新的:是的,这对于版本控制非常重要.我可以构建新版本的 Web 服务并使用旧的客户端代码.如果您同时构建客户端和服务,并且您确定将始终同时部署新版本的客户端和服务,您可以使用 Andrew 的建议.

Service reference is not up to date: Yes this is very important for versioning. I can build new version of web service and use the old client code. If you are building both client and service and you are sure that new versions of client and service will be always deployed in the same time you can use Andrew's suggestion.

类型无法序列化:Web 服务正在使用可互操作的格式进行数据交换.你认为编译器应该如何知道类型是否可序列化?它应该在每次构建期间运行所有数据类型的序列化吗?正如约翰所说,这可以通过适当的测试策略轻松发现.

Type can't be serialized: Web services are using interoperable format for data exchange. How do you think the compiler should know if the type is serializable? Should it run the serialization of all data types during each build? As John suggested this can be easily discovered by proper testing strategy.

服务尝试传递比客户端允许的更多数据:这是什么意思?您的意思是服务可以传递由于服务的新版本而客户端不知道的其他字段吗?在这种情况下,您会抱怨最重要的版本控制功能之一.或者你的意思是服务可以发送比客户端允许的更大的消息?在那种情况下,服务应该如何知道未知客户端上允许的大小?MaxReceiveMessage 大小用于防御拒绝服务攻击,它由接收方控制.如果您需要在通信中处理动态消息大小,则必须对其进行编码.

The service tryes to pass more data then client allow: What do you mean by that? Do you mean that service can pass additional fields which are not known to client because of new version of the service? In that case you are complaining about one of the most important versioning features. Or do you mean that service can send bigger message than client allows? In that case how should the service know what size is allowed on the unknown client? MaxReceiveMessage size is defence against Denial of service attack and it is controlled by receiving side. If you need to handle dynamic message size in your communication you have to code it.

隐藏错误:默认情况下,每个服务的行为都有这个配置:

Hiding errors: By default each service has this configuration in its behavior:

<serviceDebug includeExceptionDetailInFault="false" />

只需将其更改为 true add WCF Tracing + 套接字跟踪 和 WCF 消息记录,您将获得MS 在 .NET 中为开发人员提供的最好的诊断工具.

Simply change this to true add WCF Tracing + socket tracing and WCF Message logging and you will get the best diagnostic arsenal MS has ever provided in .NET to developers.

这篇关于帮助调试 WCF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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