调试WCF

来源:互联网 发布:windows.old可以移动吗 编辑:程序博客网 时间:2024/05/18 02:41

在调用WCF的时候经常会被not Found 404 这样的异常信息搞得一头雾水,到底什么原因呢,WCF并没有返回给我们这里我提供一方法帮助把元凶找出来:

首先在WCF端要添加ServiceBehavior属性并设置IncludeExceptionDetailInFaults值为true

 [ServiceBehavior(IncludeExceptionDetailInFaults=true)]

public class GuestService : IGuestService

其次在客户端在调用WCF服务的时候要添加

bool registerResult = WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);

bool httpsResult = WebRequest.RegisterPrefix("https://", WebRequestCreator.ClientHttp);

这样元凶找到了。。。。。

原创粉丝点击