抛出故障代码(“接收器”)但以“服务器”响应

发布于 2024-12-04 08:41:11 字数 955 浏览 0 评论 0原文

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

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://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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

守望孤独 2024-12-11 08:41:11

试试这个:

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 故障生成的接受答案不正确的 SOAP 1.1 错误代码值

编辑:您发布的错误消息中的 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。请参阅备注部分。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文