Flex调用Webservice时可能产生的所有错误,监控哪些错误
判断web服务是否没有方法,是否路径错误,是否编码错误,是否解码错误,等等错误
由于网上很少有相关资料,我自己整理,查看sdk总结而得
private var webserviceURL:WebService = new WebService();
webserviceURL.addEventListener(LoadEvent.LOAD,loadWebHandle);
webserviceURL.addEventListener(FaultEvent.FAULT,webFaultHandle);
webserviceURL.addEventListener(ResultEvent.RESULT,rezultHandle);
private function loadWebHandle(e:LoadEvent):void{
webserviceURL.removeEventListener(FaultEvent.FAULT,webFaultHandle);
webserviceURL.removeEventListener(LoadEvent.LOAD,loadWebHandle);
trace("加载完成");
}
private function webFaultHandle(e:FaultEvent):void{
webserviceURL.removeEventListener(FaultEvent.FAULT,webFaultHandle);
webserviceURL.removeEventListener(LoadEvent.LOAD,loadWebHandle);
trace("调用错误");
}
private function rezultHandle(e:ResultEvent):void{
webserviceURL.removeEventListener(FaultEvent.FAULT,webFaultHandle);
webserviceURL.removeEventListener(LoadEvent.LOAD,loadWebHandle);
trace("调用成功");
}
Operation 中可能产生的错误
var fault2:Fault = new Fault("EncodingError", errorMsg);
var fault2:Fault = new Fault("DecodingError", errorMsg);
var fault:Fault = new Fault("Client.MustUnderstand", msg);
var errMsg:String = "Cannot invoke method " + name + " as WSDL did not load successfully";
dispatchRpcEvent(createFaultEvent("Client.InvalidWSDL", errMsg));
F("Client.NoSuchMethod", "Couldn't find method '" + name + "' in service."
WebServic 中可能产生的错误
//mustSpecifyWSDLLocation
var fault:Fault = new Fault("Client.WSDL", message);
//destinationOrWSDLNotSpecified
var fault:Fault = new Fault("Client.WSDL", message);
//unexpectedException
var fault:Fault = new Fault("WSDLError", message);
var fault:Fault = new Fault("ConcurrencyError", message);
举例:
<mx:WebService id="ws_UserControl" fault="wsfault(event)"
wsdl="http://172.*.*.11:8080/cb_test/user?wsdl"
useProxy="false" showBusyCursor="true" requestTimeout="10">
<mx:operation name="login" result="result(event)" fault="fualt(event)" />
</mx:WebService>
private function wsfault(event:FaultEvent)
{
var str:String = event.fault.FaultCode;
//根据str来判断错误类型,如果是WSDLError,表明是unexpectedException,以此类推
}
private function fault(event:FaultEvent)
{
var str:String = event.fault.FaultCode;
//根据str来判断错误类型,如果是Client.NoSuchMethod,表明没有该方法,以此类推,以上operation中的均可以通过此来判断
}