我正在使用Java客户端调用WCF Web服务(基于SOAP)。使用apache cxf wsdl2java实用程序生成客户端。 当被调用的服务响应错误时,我无法使用catch(javax.xml.ws.soap.SOAPFaultException)处理它,但是当我使用SoapUI调用服务时,我看到一个带有错误信封的有效soap响应。 代码段:
try{
iServiceInterface.postDataToSPOnline(USERNAME, PASSWORD,loExpense); }
catch(SOAPFaultException soapEx){
try {
//Not Invoked
System.out.println(“SOAPFaultException”);
} catch(Exception exp) {
//Not Invoked
System.out.println(“Exception”);
} finally {
//Control reaches here post calling the service
System.out.println(“Finally”);
}
响应时返回错误时调用服务的SoapUI响应:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</faultcode>
<faultstring xml:lang="en-US">Object reference not set to an instance of an object.</faultstring>
<detail>
<ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<HelpLink i:nil="true"/>
<InnerException i:nil="true"/>
<Message>Object reference not set to an instance of an object.</Message>
<StackTrace>at
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace>
<Type>System.NullReferenceException</Type>
</ExceptionDetail>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
非常感谢您在处理此方案时提出的建议。
谢谢, Wajid