开发者

throwing faultcode("Receiver") but responding with "Server"

I'm throwing a FaultCode of Receiver, but the client is getting back "s:Server" as a response faultcode. How can i get a response of "s:Receiver"?

My code:

throw new FaultException<System.ApplicationException>(new System.ApplicationException("My application broke"), new FaultReason("because i said so"), new FaultCode("Receiver"));

response:

<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://sc开发者_高级运维hemas.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>


Try this:

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"));

See accepted answer to .NET WCF faults generating incorrect SOAP 1.1 faultcode values

EDIT: The http://schemas.xmlsoap.org/soap/envelope/ namespace in the fault message you posted indicates that you are using a binding based on SOAP 1.1. SOAP 1.1 only supports the following fault codes: VersionMismatch, MustUnderstand, Client, and Server. SOAP 1.2 supports: VersionMismatch, MustUnderstand, DataEncodingUnknown, Sender, and Receiver. The reason you are unable to specify the Sender fault code may be due to the binding. Try specifying the Client fault code instead. I got the fault code lists from http://msdn.microsoft.com/en-us/library/system.servicemodel.faultcode.aspx. See the Remarks section.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜