Skip to main content

Microsoft Silverlight

Answered Question Handling PrincipalPermission failureRSS Feed

(0)

dnorm252
dnorm252

Member

Member

0 points

1 Posts

Handling PrincipalPermission failure

I'm using PrincipalPermission attributes on my WCF service methods. They are all working correctly, but when the user fails the permission required to run the method the error trickes down to the client and I get the typical "not found" error. Is there any way of handling this gracefully? It doesn't seem to throw a SecurityException down to the client.

I can accomplish this by removing the attributes and creating an instance of a PrincipalPermission and calling it's Demand method. This gives me full control and allows me to catch the error if one does occur.

 What I'd like to do is use the attributes if possible while still having the ability to catch and process the error.

Allen Chen – MSFT
Allen Ch...

Star

Star

13862 points

1,803 Posts

Answered Question

Re: Handling PrincipalPermission failure

Hi,

Actually sever does send fault message to Silverlight. However, unfortunately due to current Silverlight limitation it cannot parse the message that intelligently.

I wrote a sample that demonstrates how to work around that. You can download it from:

http://cid-2fa13ebc6cc8e80f.skydrive.live.com/self.aspx/Public/MessageInspectorSL.zip

The key is to use MessageInspector to catch the response at server and then change the response. We also need to add an extra property in our DataContract to pass exception Message. In my sample only one property is used for simplicity. If there are more than one OperationContracts we need to add more code logic to know which response to return. OperationContext.Current.IncomingMessageHeaders.Action can be used to know what response should be sent back.

This is not an elegant solution because it couples a lot of things but it can solve the specific issue as you mentioned.

Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities