ajax - Cant get info from FaultExceptions (javascript) -
until have used webservice asmx call javascript. has been working fine, because needed control on serialization, trying switch datacontracts , wcf. however, believe there have misunderstood, because im trying catch faultexceptions client code (javascript), errorcode im receiving is: (translated, might not accurate)
"the server not handle request because of intern error. can more info error activate includeexceptiondetailinfaults..."
i have tried set includeexceptiondetailinfauls true gives info, far understood, whole point throwing faultexceptions hide exceptions user, , throw little info? im trying ierrorhandler, have created simpler example:
the svc:
[servicecontract(namespace = "")] [aspnetcompatibilityrequirements(requirementsmode = aspnetcompatibilityrequirementsmode.allowed)] public class wcftest { // use http get, add [webget] attribute. (default responseformat webmessageformat.json) // create operation returns xml, // add [webget(responseformat=webmessageformat.xml)], // , include following line in operation body: // weboperationcontext.current.outgoingresponse.contenttype = "text/xml"; [operationcontract] public string dook() { // add operation implementation here return "success"; } [operationcontract] public string dofail() { faultreason reason = new faultreason("fail <- :)"); throw new faultexception(reason); return "success"; } } which included scriptmanager, , called following javascript:
<a href="java script:void(0);" onclick="dook()">ok</a><br /> <a href="java script:void(0);" onclick="dofail()">fail</a> <script> function dook() { wcftest.dook( function (result) { alert("dook success: "+result); }, function (result) { alert("dook failed: " + result); }) } function dofail() { wcftest.dofail( function (result) { alert("dofail success: " + result); }, function (result) { alert("dofail failed: " + result); }) } </script> and service model:
<system.servicemodel> <behaviors> <servicebehaviors> <behavior name="wcftestaspnetajaxbehavior"> </behavior> </servicebehaviors> <endpointbehaviors> <behavior name="wcftestaspnetajaxbehavior"> <enablewebscript /> </behavior> </endpointbehaviors> </behaviors> <servicehostingenvironment aspnetcompatibilityenabled="true" multiplesitebindingsenabled="true" /> <services> <service name="wcftest"> <endpoint address="" behaviorconfiguration="wcftestaspnetajaxbehavior" binding="webhttpbinding" contract="wcftest" /> </service> </services> </system.servicemodel> ive tried mark dofail method combinations of:
[faultcontract(typeof(faultexception))] [faultcontract(typeof(faultreason))] have misunderstood something? shouldnt able exception info throwing faultexception without having set includeexceptiondetailinfaults true?
useful resources:
main steps:
- create own error handler impelemting ierrorhandler interface
- create subclass of webhttpbehavior , replace default error handler own error handler
- plug-in custom/extended behavior using custom servicehostfactory or define behaviorextension in web.config
Comments
Post a Comment