我正在使用 .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><![CDATA[<error xmlns="urn:company:schema:errordetail:v01"><errorCode>1000</errorCode><highestSeverity>8</highestSeverity><errorDetails count="1"><errorDetail><errorType>1</errorType><errorSeverity>8</errorSeverity><errorDescription>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.</errorDescription><errorNamespace>urn:company:schema:sendinvoice:rq:v01</errorNamespace><errorNode>CompanyName</errorNode><errorLine>1</errorLine><errorColumn>2556</errorColumn><errorXPath/><errorSource/></errorDetail></errorDetails></error>]]></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 服务通信的原因。这个用户有一个类似的问题,但他的问题的原因与我的不同,因为我可以在跟踪中看到故障详细信息:Does WCF FaultException<T> support interop with a Java web service Fault
任何帮助将不胜感激。