Skip to main content
Home Forums Silverlight Programming Accessing Web Services with Silverlight Handling PrincipalPermission failure
1 replies. Latest Post by Allen Chen – MSFT on November 6, 2009.
(0)
dnorm252
Member
0 points
1 Posts
11-02-2009 9:32 AM |
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 Ch...
Star
13862 points
1,803 Posts
11-06-2009 3:53 AM |
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.