【问题标题】:Web service client receiving generic FaultException rather than FaultException<T>Web 服务客户端接收通用 FaultException 而不是 FaultException<T>
【发布时间】:2010-05-05 09:12:48
【问题描述】:

我正在使用 .NET Web 服务客户端连接到 Java Axis2 Web 服务。客户端本身以 .NET 3.5 框架为目标。包装客户端 DLL 的应用程序是 2.0。我不确定这是否有任何影响。

我已通过电子邮件收到 WSDL 和 XSD。我使用 svcutil 构建了我的代理类。虽然我能够成功发送消息,但当出现问题时,我无法找出正确的故障。在下面的示例中,错误总是被通用的 FaultException 拾取。

catch (FaultException<InvoiceErrorType> fex)
{
    OnLog(enLogLevel.ERROR, fex.Detail.ErrorDescription);
}
catch (FaultException gfex)
{
    OnLog(enLogLevel.ERROR, gfex.Message);
}

代理客户端似乎具有适用于 FaultContract 的属性:

// CODEGEN: Generating message contract since the operation SendInvoiceProvider_Prod is neither RPC nor document wrapped.
[OperationContractAttribute(Action = "https://private/SendInvoiceProvider", ReplyAction = "*")]
[FaultContractAttribute(typeof(InvoiceErrorType), Action = "https://private/SendInvoiceProvider", Name = "InvoiceError", Namespace = "urn:company:schema:entities:base")]
[XmlSerializerFormatAttribute(SupportFaults = true)]
[ServiceKnownTypeAttribute(typeof(ItemDetail))]
[ServiceKnownTypeAttribute(typeof(Supplier))]
OutboundComponent.SendInvoiceProviderResponse SendInvoiceProvider_Prod(OutboundComponent.SendInvoiceProvider_Request request);

我已启用跟踪,并且可以看到返回的故障内容,但 .NET 未将其识别为 InvoiceError。完整的 SOAP 错误是:

<soapenv:Fault>
    <faultcode xmlns="">soapenv:Client</faultcode>
    <faultstring xmlns="">Message found to be invalid</faultstring>
    <faultactor xmlns="">urn:SendInvoiceProvider</faultactor>
    <detail xmlns="">
        <InvoiceError xmlns="urn:company:schema:entities:common:invoiceerror:v01">
                <ErrorID>100040</ErrorID>
                <ErrorType>UNEXPECTED</ErrorType>
                <ErrorDescription>&lt;![CDATA[&lt;error xmlns="urn:company:schema:errordetail:v01"&gt;&lt;errorCode&gt;1000&lt;/errorCode&gt;&lt;highestSeverity&gt;8&lt;/highestSeverity&gt;&lt;errorDetails count="1"&gt;&lt;errorDetail&gt;&lt;errorType&gt;1&lt;/errorType&gt;&lt;errorSeverity&gt;8&lt;/errorSeverity&gt;&lt;errorDescription&gt;cvc-complex-type.2.4.a: Invalid content was found starting with element 'CompanyName'. One of '{"urn:company:schema:sendinvoice:rq:v01":RoleType}' is expected.&lt;/errorDescription&gt;&lt;errorNamespace&gt;urn:company:schema:sendinvoice:rq:v01&lt;/errorNamespace&gt;&lt;errorNode&gt;CompanyName&lt;/errorNode&gt;&lt;errorLine&gt;1&lt;/errorLine&gt;&lt;errorColumn&gt;2556&lt;/errorColumn&gt;&lt;errorXPath/&gt;&lt;errorSource/&gt;&lt;/errorDetail&gt;&lt;/errorDetails&gt;&lt;/error&gt;]]&gt;</ErrorDescription>
                <TimeStamp>2010-05-04T21:12:10Z</TimeStamp>
        </InvoiceError>
    </detail>
</soapenv:Fault>

我注意到错误上定义的命名空间:

<InvoiceError xmlns="urn:company:schema:entities:common:invoiceerror:v01">

这在生成的代理类中看不到,在 WSDL 中也看不到。接口 WSDL 将错误模式命名空间定义为:

<xs:import namespace="urn:company:schema:entities:base" schemaLocation="InvoiceError.xsd"/>

这可能是 .NET 客户端无法正确解析键入的故障异常的原因吗?

我无法控制 Web 服务本身。我看不出 .NET 不能与 Java Axis2 Web 服务通信的原因。这个用户也有类似的问题,但是他的问题原因不能和我的一样,因为我可以在 trace 中看到故障细节:Does WCF FaultException<T> support interop with a Java web service Fault

如有任何帮助,我们将不胜感激。

【问题讨论】:

  • 在发布问题之前这可能是显而易见的事情,但我更改了代理类中的命名空间以匹配返回的内容,而不是 WSDL 所说的内容和错误异常被正确捕获。因此,该问题是由 WSDL 和 Web 服务之间的不匹配引起的。关闭您自己回答的问题的程序是什么?
  • 在“您的答案”的大框中回答问题,然后单击它旁边的小复选标记。您还应该多次为自己投票以取得好成绩...好吧,我把最后一部分做了,但第一个是正确的。已经回答问题了!!! ;-)

标签: .net-3.5 axis2 webservice-client


【解决方案1】:

在 WSDL 中为自定义故障类型提供的命名空间与引发的故障命名空间不匹配。结果,.NET 客户端无法正确反序列化故障。

换句话说,第三方公司需要更改 WSDL 或更改正在引发的错误的命名空间。

帮助您查明此类问题的最有用工具是设置跟踪:http://msdn.microsoft.com/en-us/library/ms732023.aspx

【讨论】:

  • 另外,不能只添加服务引用,因为 svcutil 默认使用 DataContractSerializer 而不是 XmlSerializer。解决方法是从命令行使用 svcutil。如果您有多个来自远程位置的嵌入式架构,则需要单独下载这些文件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-01
  • 1970-01-01
  • 2011-02-08
  • 2013-05-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多