A custom exception thrown by a web service that was not visible to the client (using shared assemblies)

I created a custom InvalidSessionException . However, trying to catch or evaluate if an exception occurred is of this type, it does not work. Bearing in mind that it is both EX is and Catch Ex , it does not evaluate the value of InvalidSessionException

 try { acc = this.fda.GetAccountHeader(this.selectedTicket.AccountId); } catch (Exception ex) { if (ex is Enterprise.Data.InformationModel.CustomExceptions.InvalidSessionException) { this.lblError.Text = Resources.Resource.error_sessionedTimedOut; this.MPError.Show(); } return; } 

I also tried (without any difference in results)

 catch (Enterprise.Data.InformationModel.CustomExceptions.InvalidSessionException ex) { this.lblError.Text = Resources.Resource.error_sessionedTimedOut; this.MPError.Show(); return; } catch (Exception ex) { return; } 

From what I can say that the exception thrown is of the correct type.

enter image description here

Additional Information:

ex.GetType().FullName = "System.ServiceModel.FaultException1[[System.ServiceModel.ExceptionDetail, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"

Is reuse enabled in the service? enter image description here

+7
c # exception web-services wcf
source share
2 answers

A loan in which a loan must be
Nintey - Nine percent of the credit for this response goes to the comment posted by Adriano Repetti on this page. I just tried this solution on my own since I had the same problem as described in the question above.

Problem
Configure Service Reference window assemblies section

Regarding the "Service Link Setting" modal window; just because you select "Reuse Types in All Referential Assemblers" does not mean that he really does - it seems like a lazy operation, and basically these links will be made if the code generated by the code matches it.

Decision
Therefore, if you actually check what you need, it seems that it will most likely be used instead of being. This is achieved by changing the "Reuse types in all referenced assemblies" switch to "Reuse types in specified referenced assemblies" (second switch option).

My supporting observations
It seems that this especially affects FaultExceptions, I don’t know why, but it is. My FaultExceptions errors in my project were generated in the service link namespace, rather than reusing them from the link assembly.

What is particularly puzzling is that namspace is specifically described when you look at the Reference.cs of the service reference code. However, it did not work until I did what I described above. Finally, I just want to point out that this is a great example of a "breaking canon" or "not canonical."

+1
source share

I believe that you need to use a strongly typed FaultException<T> . Something like...

DISCLAIMER: The following code has not been tested

SERVER

 [ServiceContract] public interface ISampleService { [OperationContract] [FaultContractAttribute(typeof(InvalidSessionException)] void SampleMethod(); } void SampleMethod() { ... throw new FaultException<InvalidSessionException>(); } 

CLIENT PARTY

 ... try { _wcfChannel.SampleMethod(); catch (FaultException<InvalidSessionException> ex) { // take appropriate action } } 

ADDITIONAL READING

+1
source share

All Articles