我抛出了接收器的故障代码,但客户端返回“s:Server”作为响应故障代码。 如何获得“s:Receiver”的响应?
我的代码:
throw new FaultException<System.ApplicationException>(new System.ApplicationException("My application broke"), new FaultReason("because i said so"), new FaultCode("Receiver"));
回复:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode>s:Server</faultcode>
<faultstring xml:lang="en-US">because i said so</faultstring>
<detail>
<ApplicationException xmlns="http://schemas.datacontract.org/2004/07/System" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:x="http://www.w3.org/2001/XMLSchema">
...
</ApplicationException>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
最佳答案
试试这个:
throw new FaultException<System.ApplicationException>(
new System.ApplicationException("My application broke"),
new FaultReason("because i said so"),
new FaultCode("Receiver", "http://schemas.microsoft.com/ws/2005/05/envelope/none"));
查看已接受的答案 .NET WCF faults generating incorrect SOAP 1.1 faultcode values
编辑:您发布的错误消息中的 http://schemas.xmlsoap.org/soap/envelope/
命名空间表明您正在使用基于 SOAP 1.1 的绑定(bind)。 SOAP 1.1 仅支持以下错误代码:VersionMismatch、MustUnderstand、Client 和 Server。 SOAP 1.2 支持:VersionMismatch、MustUnderstand、DataEncodingUnknown、Sender 和 Receiver。您无法指定发件人故障代码的原因可能是由于绑定(bind)所致。请尝试指定客户端故障代码。我从http://msdn.microsoft.com/en-us/library/system.servicemodel.faultcode.aspx获取故障码列表。请参阅备注部分。
关于wcf - 抛出错误代码 ("Receiver")但响应为 "Server",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7420742/