WCF:FaultContract(typeof(ExceptionDetail))问题
我已经为我的操作合约添加了属性 [FaultContract(typeof(ExceptionDetail))]
。当我尝试将服务添加到客户端应用程序时,出现此错误 - “自定义工具错误:无法为服务引用“ServiceReference1”生成代码。请检查其他错误和警告消息以了解详细信息。”< /code>
但是当我注释掉FaultContract 属性时,我可以在我的客户端应用程序中添加wcf 服务引用。
I have put the attribute [FaultContract(typeof(ExceptionDetail))]
for my operation contract. When I am trying to add the service to a client application, I get this error - "Custom tool error: Failed to generate code for the service reference 'ServiceReference1'. Please check other error and warning messages for details."
But when I comment out the FaultContract Attribute, I am able to add the wcf service reference th' my client app.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
拥有FaultContracts的目的是首先能够从服务传回SOAP错误,这不会破坏服务器和客户端之间的通信通道(优雅且可互操作地处理.NET异常等错误条件),其次,使用FaultContracts,您的服务器将抛出类型错误(
FaultException
),并且您的客户端可以捕获这些错误。如果您希望或需要真正具有互操作性,则需要:
如果你控制了电线的两端,并且两端都是.NET,那么你可以简化这一点:在服务器上,处理所有.NET异常并将它们变成例如
FaultException
,即就是,创建一个“错误(无论什么 .NET 异常)”,然后在客户端捕获这些类型的FaultException 并处理它们:然后在您的实现中使用:
The point of having FaultContracts is to make it possible to first of all pass back SOAP faults from the service which will not break the communication channel between the server and the client (handling error conditions like .NET exceptions gracefully and interoperably), and secondly, using FaultContracts, your server than throw typed faults (
FaultException<T>
) and your client can catch those.If you want or need to be really interoperable, you need to:
If you control both ends of the wire and both ends are .NET, then you can simplify this by one step: on the server, handle all .NET exceptions and turn them into e.g.
FaultException<ArgumentOutOfRangeException>
, that is, create a "fault of (whatever .NET exception)" and then on the client, catch those typed FaultException and handle them:and then in your implementation, use this:
删除该
FaultContract
,并配置includeExceptionDetailInFaults
:Remove that
FaultContract
, and instead configureincludeExceptionDetailInFaults
:使用 http://msdn.microsoft.com/en- 中的服务跟踪查看器工具us/library/ms732023.aspx,查看活动跟踪。
Use Service Trace Viewer tool from http://msdn.microsoft.com/en-us/library/ms732023.aspx, to view the activity trace .
几分钟前我也遇到了同样的问题。
这是由于缺少默认构造函数造成的。另请记住,所有属性都必须具有公共 get/set 访问器。
I had the same problem few minutes ago.
It was due to the absence of a default constructor. Also remember that all properties must have public get/set accessors.