Sure, good question...
First, I have the Attribute class... in that class I have:
Sub New(ByVal useAuthentication As Boolean)
Throw New SoapException("hellp!!!!!", SoapException.ClientFaultCode)
End Sub
Now from the class that is using the Atrribute, I have..
<WebMethod(), UseAuthenticationManager(True)> _
Public Function Test() As String
' Do nothing, exception should have been thrown from Attribute
constructor!
End Function
If you could let me know whats going on that would be great. The attribute
is being detected, but no matter what I do from the constructor, it doesnt
seem to matter (like throw an exception)
thanks,
> Who says that you cannot throw exceptions from the contructor? Do you get an
> error?
[quoted text clipped - 19 lines]
> >
> > thanks...
Mattias Sjögren - 20 Sep 2005 19:13 GMT
>If you could let me know whats going on that would be great. The attribute
>is being detected, but no matter what I do from the constructor, it doesnt
>seem to matter (like throw an exception)
When are you expecting the exception to be thrown? It will not happen
at compile time or when the method is called if that's what you
expect.
Why do you want to do this anyway? The design idea seems weird at
best.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
aiKeith - 21 Sep 2005 13:24 GMT
Here is exactly why I want to do this.
I am using wse to secure a web service. While an exception gets thrown back
if the credentials are not met, nothing happens if they are not. Therefore
you have to do some check for the tokens in the beginning of the method you
want to secure. Instead I wanted to secure a method declaratively... just
like CAS works in .NET - what is wierd about that...
for instance:
<UseSecurity(True), WebMethd()>_
Just like CAS works
<SecurityAction.Demand... blah blah>
> >If you could let me know whats going on that would be great. The attribute
> >is being detected, but no matter what I do from the constructor, it doesnt
[quoted text clipped - 8 lines]
>
> Mattias
Richard Blewett [DevelopMentor] - 21 Sep 2005 14:21 GMT
Unfortunately for you, CAS has an advantage that you do not, it is part of the runtime and therefore the runtime ensures its involvement. Normal custom attributes only come into effect when code that is interested in them executes. Unfortunately you checking code isn't getting executed as custom attribute instances are only created when someone calls GetCustomAttributes.
You will not be able to do what CAS does because your code is not part of the runtime. However, I guess you could derive from ConotextBoundObject and intercept the method call, doing your checking there
Regards
Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
Here is exactly why I want to do this.
I am using wse to secure a web service. While an exception gets thrown back
if the credentials are not met, nothing happens if they are not. Therefore
you have to do some check for the tokens in the beginning of the method you
want to secure. Instead I wanted to secure a method declaratively... just
like CAS works in .NET - what is wierd about that...
for instance:
<UseSecurity(True), WebMethd()>_
Just like CAS works
<SecurityAction.Demand... blah blah>
aiKeith - 21 Sep 2005 14:40 GMT
Richard - thank you for your feedback.
Well thats not very good news. Would anyone know what the recommended
solution to this using wse 2.0 ? I dont want to intercept EVERY method call,
just the methods that require credentials to access them.
Here's my problem with the current solution
<WebMethod()>_
Public Function PleaseBeSecure()
CheckforToken()
' a bunch of super secret code.
End Function
The problem with this is it would be WAY TO EASY to accidentially remove the
CheckforToken(), whereas if it was an attribute, it would stand out more.
Any suggestions?
> Unfortunately for you, CAS has an advantage that you do not, it is part of the runtime and therefore the runtime ensures its involvement. Normal custom attributes only come into effect when code that is interested in them executes. Unfortunately you checking code isn't getting executed as custom attribute instances are only created when someone calls GetCustomAttributes.
>
[quoted text clipped - 23 lines]
> <SecurityAction.Demand... blah blah>
>