Andrea Laperuta wrote:
Post the code of the attribute and WebMethod.
// This is the web method. Results are the same whether
// I decorate it with a WebMethod attribute or not.
[StringAttribute("blah")]
public string getResultCode()
{
return mResult;
}
// StringAttribute is my custom attribute that I have used many times:
public class StringAttribute: System.Attribute
{
private string mString;
public StringAttribute(string s): base()
{
mString = s;
}
public override string ToString()
{
return mString;
}
}
// I use this method to get the value of the StringAttribute passing
// the web service object and the method name "getResultCode".
// This works fine in all other instances including from within
// the web service itself.
// When I debug through this code, obj contains a
// WebMethod attribute when I add that additional attribute,
// but not my StringAttribute.
public static string getAttribValue(Object obj, string memberName)
{
// I presume this is an array to account for overloaded methods...
MemberInfo[] mi = obj.GetType().GetMember(memberName);
if ( mi.Length > 0 )
{
foreach( MemberInfo currentMI in mi )
{
Attribute ca = Attribute.GetCustomAttribute(currentMI,
typeof(StringAttribute));
if ( ca != null )
{
return attrToString( ca );
}
}
return string.Empty;
}
else
{
return string.Empty;
}
}