如何获取 Dynamics AX 中 SOAP 错误的详细信息?

发布于 2024-08-19 07:07:04 字数 980 浏览 12 评论 0原文

我当前正在使用服务引用和生成的 .NET 类与 AX 中的外部 SOAP 服务进行通信。除了如何处理 SOAP 错误之外,一切都进展顺利。理想情况下,这不会发生,但有时 SOAP 服务器(我也控制它)会抛出带有“代码”和“消息”的 SOAP 错误。代码及其各自消息的一些示例:

  • “INVALID_API_KEY”/“使用了无效的 API 密钥。”
  • “INVALID_CUSTOMER_ID”/“传递了无效的客户 ID (%d)”。

这些错误代码是在 WSDL 中定义的,因此当抛出这些错误时,我自然可以将一些经过清理的消息传回给用户。不幸的是,我在通过 X++ 深入了解抛出了哪个 SOAP 错误时遇到了问题,以便我可以向用户显示经过净化的失败解释。目前我的代码如下所示:

try
{
    new InteropPermission(InteropKind::ClrInterop).assert();   

    // ... code making SOAP calls

    CodeAccessPermission::revertAssert();
}
catch(Exception::CLRError)
{
    warning(AifUtil::getClrErrorMessage());
}

这可以很好地处理 SOAP 错误,它产生的错误如下: " Type 'System.ServiceModel.Channels.ReceivedFault' in assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' 未标记为可序列化。”

我尝试深入研究 .NET 基类,但是 ServiceModel(以及随后的)用于将 SOAP 错误(类阶梯中的FaultException)转换为人类可读消息的其他类被掩盖了。

谁能告诉我一些关于如何最好地获取实际故障代码/消息的见解?谢谢!

I'm currently communicating with an external SOAP service within AX using the a service reference and the generated .NET class. Everything is working out greatly with the exception of how to handle SOAP faults. Ideally, this doesn't happen, but sometimes the SOAP server (which I control as well) throws a SOAP fault with a "code" and a "message". Some examples of codes and their respective messages:

  • "INVALID_API_KEY" / "An invalid API key was used."
  • "INVALID_CUSTOMER_ID" / "An invalid customer Id was passed (%d)".

These error codes are defined in the WSDL, so when these faults are thrown I can naturally pass back some sanitized message to the user. Unfortunately, I'm having a problem drilling down through X++ to figure which SOAP fault has been thrown so that I can display back a sanitized explanation of failure back to my user. Currently my code looks like:

try
{
    new InteropPermission(InteropKind::ClrInterop).assert();   

    // ... code making SOAP calls

    CodeAccessPermission::revertAssert();
}
catch(Exception::CLRError)
{
    warning(AifUtil::getClrErrorMessage());
}

This handles the SOAP fault well enough, the error it produces is the following: " Type 'System.ServiceModel.Channels.ReceivedFault' in assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable."

I have tried drilling down the base .NET classes, but the ServiceModel (and subsequently) the other classes for translating the SOAP fault (FaultException down the class ladder) into a human readable message are obscured.

Can anyone lend me some insight on how best to get at the actual fault code/message? Thanks!

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

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

发布评论

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

评论(1

两人的回忆 2024-08-26 07:07:04

您可以使用 wcf 跟踪 http://msdn.microsoft.com/en-us /library/ms733025.aspx

或者您可以使用网络嗅探器(如 fiddler)检查响应。

You could use wcf tracing http://msdn.microsoft.com/en-us/library/ms733025.aspx

Or you could check the response using a network sniffer like fiddler.

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