抛出faultcode(“Receiver”)但响应“Server”

时间:2011-09-14 17:52:40

标签: wcf soap faultexception

我正在抛出一个Receiver的FaultCode,但客户端正在回复“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>

1 个答案:

答案 0 :(得分:3)

试试这个:

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的绑定。 SOAP 1.1仅支持以下错误代码:VersionMismatch,MustUnderstand,Client和Server。 SOAP 1.2支持:VersionMismatch,MustUnderstand,DataEncodingUnknown,Sender和Receiver。您无法指定发件人故障代码的原因可能是绑定。请尝试指定客户端故障代码。我从http://msdn.microsoft.com/en-us/library/system.servicemodel.faultcode.aspx获得了错误代码列表。请参阅备注部分。