Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / March 2005

Tip: Looking for answers? Try searching our database.

Can't get my custom attribute from web method

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brad Wood - 16 Feb 2005 22:01 GMT
I've added my custom attribute to a web service's method.  When I
consume the web service and attempt to check the value of the attribute,
it's not there, but the WebMethod attribute is.  My attribute descends
from the same System.Attribute class as the WebMethod attribute does.

Can anyone tell me why it has gone missing?
Andrea Laperuta - 18 Feb 2005 11:21 GMT
Post the code of the attribute and WebMethod.

Bye.

> I've added my custom attribute to a web service's method.  When I
> consume the web service and attempt to check the value of the attribute,
> it's not there, but the WebMethod attribute is.  My attribute descends
> from the same System.Attribute class as the WebMethod attribute does.
>
> Can anyone tell me why it has gone missing?
Brad Wood - 23 Feb 2005 16:23 GMT
> 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;
  }

}
Dilip Krishnan - 25 Feb 2005 18:51 GMT
Where are you trying to check for this Attribute? If its in the proxy
you will not find it there

>> Post the code of the attribute and WebMethod.
>
[quoted text clipped - 50 lines]
>
> }

Signature

HTH
Regards,
Dilip Krishnan
MCAD, MCSD.net
dkrishnan at geniant dot com
http://www.geniant.com

Brad Wood - 28 Feb 2005 15:45 GMT
> Where are you trying to check for this Attribute? If its in the proxy
> you will not find it there

I don't understand the question, "If its in the proxy
you will not find it there".  ???
Dilip Krishnan - 01 Mar 2005 01:10 GMT
If you try to check the web service attributes in a web service proxy
class you will not find it there. Web service proxy class is the class
that you use to call methods on a web service. Usually has the same name
as the service and can be created by "Adding web reference..."

>> Where are you trying to check for this Attribute? If its in the proxy
>> you will not find it there
>
> I don't understand the question, "If its in the proxy
> you will not find it there".  ???

Signature

HTH
Regards,
Dilip Krishnan
MCAD, MCSD.net
dkrishnan at geniant dot com
http://www.geniant.com

Brad Wood - 01 Mar 2005 19:51 GMT
> If you try to check the web service attributes in a web service proxy
> class you will not find it there.

That's not true; as I mentioned, the WebMethod attribute is present in
the proxy object and my custom attribute was present in past builds.
Dilip Krishnan - 02 Mar 2005 03:39 GMT
Hello Brad,

Are you sure you had a WebMethod attribute in your proxy? I would seriously
doubt that

HTH
Regards,
Dilip Krishnan
MCAD, MCSD.net
dkrishnan at geniant dot com
http://www.geniant.com

>> If you try to check the web service attributes in a web service proxy
>> class you will not find it there.
>>
> That's not true; as I mentioned, the WebMethod attribute is present in
> the proxy object and my custom attribute was present in past builds.
Brad Wood - 02 Mar 2005 14:57 GMT
> Hello Brad,
>
> Are you sure you had a WebMethod attribute in your proxy? I would
> seriously doubt that

When I programmatically search through the attribute collection of my
proxy object (from my test harness), I do in fact find the
WebMethodAttribute object in there.  And I am quite certain that I
*used* to find my custom attribute as well, but I was using Delphi.net
at the time, so it undoubtedly created the proxy dll differently.

BTW, where the heck is the proxy dll?  Is it buried in the framework
folders?  I can't find it.
Andrea Laperuta - 25 Feb 2005 19:19 GMT
Sorry  for the long time you waited, but I was busy, however I tried your
code and I have to tell you that works fine on my pc!

I think that the problem isn't in the code.

Let me now if you have more clues...

Bye.

> > Post the code of the attribute and WebMethod.
>
[quoted text clipped - 50 lines]
>
> }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.