我正在使用.NET Web服务客户端连接到Java Axis2 Web服务。客户端本身的目标是.NET 3.5框架。包装客户端DLL的应用程序是2.0。我不确定这是否有任何影响。Web服务客户端接收通用FaultException而不是FaultException <T>
我已经通过电子邮件得到了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
任何帮助将感激地收到。
在发布问题之前,这可能是显而易见的事情,但我更改了我的代理类中的命名空间,以匹配返回的内容,而不是WSDL所说的,并且错误异常被正确捕获。 因此,问题是由WSDL和Web服务之间的不匹配造成的。 关闭你自己回答的问题的过程是什么? – Junto 2010-05-05 09:39:26
在显示“您的答案”的大框中回答问题,然后单击旁边的小复选标记。你也应该好好几次,好好衡量自己,好吧,我做了最后一部分,但第一部分是正确的。已经回答了这个问题! ;-) – 2010-05-05 17:21:21