wcf - 抛出错误代码 ("Receiver")但响应为 "Server"

标签 wcf soap faultexception

我抛出了接收器的故障代码,但客户端返回“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/

相关文章:

c# - 不一致的可访问性 : Parameter type is less accessible than method with WCF MEX

WCF - 调用无效服务(它仍然是同步的)吗?

c# - 不显示堆栈跟踪的 wcf 异常

c# - 如果字段是实例成员,则回调处理程序异常

java - 如何为使用 X.509 保护的 WCF 服务创建 Java 客户端?

wcf - 必须使用带有动词 SET 的 APP 对象的确切标识符

c# - 使用 Java 和 C# 的 SOAP - 客户端对象处理

c++ - 无法使用 OpenSSL 验证服务器证书

php - SOAP 错误 : Parsing WSDL: Couldn't load from 'website ' failed to load external entity

c# - 单元测试 WCF 错误