.net - Force WCF Host into Faulted State -


is there way force wcf host fault? (more rest based wcf host.) there exception type can thrown cause host fault? if exception can't host faulted state, could?

in "api_root" function below, i've thrown several different types of exceptions, , either caught exception handler, or cause whole process fail(outofmemoryexception).

some example code. in vb, c# appreciated.

<servicecontract(name:="api", namespace:="urn:test")> public interface iwebserviceapi      <operationcontract()>     <webget(uritemplate:="getobject")>     function api_root() object  end interface  <servicebehavior(instancecontextmode:=instancecontextmode.percall, includeexceptiondetailinfaults:=true)> public class webserviceapi     implements iwebserviceapi      public function api_root() object implements iwebserviceapi.api_root          //throw exception type causes host fail          return new object()     end function  end class  function startservice()      _service = new webservicehost(gettype(webserviceapi), baseaddresses)      _service.open()      addhandler _service.opened, addressof me.opened     addhandler _service.closed, addressof me.closed     addhandler _service.faulted, addressof me.faulted  end function  sub faulted(sender object, e eventargs)      //handle falted service here  end sub 

the failed state not exist. but, if talking generic way close host can try:

system.servicemodel.operationcontext.current.host.close(); 

if failure mandatory you, state you're looking faulted. host object (whose type system.servicemodel.channels.communicationobject) has method named fault(), isn't public, you'll able call bit of reflection. should make host transitioning faulted state.

update. can use host derived webservicehost:

class mywebservicehost : system.servicemodel.web.webservicehost {     public mywebservicehost(type servicetype, params uri[] baseaddresses)     : base (servicetype, baseaddresses)     {      }      public void fail()     {         base.fault();     } }