Silverlight client does not understand the error

I have a WCF service that throws an exception that I am trying to catch in my silverlight client code. I am using Undeclared Faults for Debugging, and this is my maintenance method:

[OperationContract]
public ServiceResponse MyWCFServiceMethod()
{
  ServiceResponse resp = new ServiceResponse ();
  //code for setting resp...

  //purposely throw error here.
  throw new FaultException(new FaultReason(new FaultReasonText("My fault Reason!")),new FaultCode("my fault code here"));
  return resp;
}

Now in my silverlight client view model in the service callback method, I try to process it like this:

private void MyServiceCallback(MyWCFServiceMethodCompletedEventArgs e)
{
   if (e.Error == null)
   {
       //proceed normally
   }
   else if (e.Error is FaultException)
   {
      FaultException<ExceptionDetail> fault = e.Error as FaultException<ExceptionDetail>;
      MessageBox.Show(fault.Detail.Message);
      MessageBox.Show(fault.Reason.ToString());
   }
} 

on this line else if (e.Error is FaultException)I still get a System.Net.WebException {The remote server returned an error: NotFound.}

These are configuration entries

<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />

This is a class of service ad.

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MySilverlightWCFService
{
 ....

This service is in another project within the same silverlight solution. Why can't my Silverlight client get an exception exception that I throw?

Thank you for your time...

+3
source
3

, , HTTP 500, Silverlight. , HTTP-, Silverlight.

Silverlight 3: ( , WCF Silverlight.)

NotFound: , HTTP 500 Silverlight. Silverlight 500, SOAP , Silverlight. , Silverlight 2 . Silverlight 3.

+2

ok, , , , - , , , !

System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.OK;

:

throw new FaultException(new FaultReason(new FaultReasonText("My fault Reason!")),new FaultCode("my fault code here"));

silverlight , , :

   //else if (e.Error is FaultException)
   else
   {
      //FaultException<ExceptionDetail> fault = e.Error as FaultException<ExceptionDetail>;
      //MessageBox.Show(fault.Detail.Message);
      FaultException fault = e.Error as FaultException;
      MessageBox.Show(fault.Reason.ToString());
   }

. !

, .

+7

Check out SilverlightFaultBehavior . It will handle the status code change for you.

+3
source

Source: https://habr.com/ru/post/1788564/


All Articles