枚举类型引起WCF的错误——“This could be due to the service endpoint binding not using the HTTP protocol”

在博客园招聘频道的开发中,调用一个WCF服务时,遇到这样的错误:

An error occurred while receiving the HTTP response to http://wwww.cnblogs.com/test.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

后来发现是因为数据库中一条记录的一个字段值是0,在程序中读取时转换为相应的枚举类型(enum),而该枚举类型没有定义0所对应的枚举值。这种情况下,转换为枚举类型不会引发异常,转换后该属性的值仍为0。但是返回给WCF客户端时,就会引发上面的异常。

解决方法很简单,只要在枚举类型中定义一下0所对应的枚举值。

posted @ 2011-01-10 18:13  dudu  阅读(3571)  评论(2编辑  收藏  举报