1

如何隐藏以下错误信息并在 WCF 中显示自定义消息?当我们在 http 请求中注入无效参数时会发生此错误

HTTP/1.0 500 Internal Server Error
Cache-Control: private
Content-Length: 494
Content-Type: text/xml; charset=utf-8
Date: Mon, 23 Jan 2012 22:34:36 GMT
X-Cache: MISS from test.int.testgroup.com
Via: 1.0 test.int.testgroup.com:80 (squid/2.6.STABLE22)
Proxy-Connection: close

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:DeserializationFailed</faultcode><faultstring xml:lang="en-US">The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'GetData'. Character reference not valid. Line 1, position 121.</faultstring></s:Fault></s:Body></s:Envelope>
4

1 回答 1

1

您将需要一个自定义 WCF 反序列化程序,它可以捕获错误并生成自定义错误消息。看看这里: http ://social.msdn.microsoft.com/Forums/en-US/wcf/thread/dcd48a7f-4494-455f-8504-cbdc372badcf/

于 2012-01-24T05:34:45.760 回答