473,503 Members | 2,075 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't get my custom attribute from web method

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?
Nov 23 '05 #1
9 4563
Post the code of the attribute and WebMethod.

Bye.

"Brad Wood" wrote:
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?

Nov 23 '05 #2
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;
}

}
Nov 23 '05 #3
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.

"Brad Wood" wrote:
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;
}

}

Nov 23 '05 #4
Where are you trying to check for this Attribute? If its in the proxy
you will not find it there

Brad Wood wrote:
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;
}

}


--
HTH
Regards,
Dilip Krishnan
MCAD, MCSD.net
dkrishnan at geniant dot com
http://www.geniant.com
Nov 23 '05 #5
Dilip Krishnan wrote:
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". ???
Nov 23 '05 #6
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..."

Brad Wood wrote:
Dilip Krishnan wrote:
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". ???


--
HTH
Regards,
Dilip Krishnan
MCAD, MCSD.net
dkrishnan at geniant dot com
http://www.geniant.com
Nov 23 '05 #7
Dilip Krishnan wrote:
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.
Nov 23 '05 #8
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
Dilip Krishnan wrote:
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.


Nov 23 '05 #9
Dilip Krishnan wrote:
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.
Nov 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1804
by: F. Da Costa | last post by:
Hi, I was wondering *why* there is a difference between the results of the following two statements. On the suface they seem to do the same (or do they?) frm => returns void ...
1
1817
by: Tim Smith | last post by:
I have a large number of methods across different classes accessed via remoting. Every time a method is executed I would like to update a status object - keeping count of the number of method...
3
3848
by: Ryan Moore | last post by:
I am trying to "tune" some user controls in ASP.NET for optimal caching. Is it possible to do a vary by param - on a Session Variable, so the page caches when a Session variable stays the same,...
7
2972
by: Shimon Sim | last post by:
I have a custom composite control I have following property
15
2118
by: Jeff Mason | last post by:
Hi, I'm having a reflection brain fog here, perhaps someone can set me on the right track. I'd like to define a custom attribute to be used in a class hierarchy. What I want to do is to...
6
9372
by: Peter Hartlén | last post by:
Hi! What's the correct syntax for the default value design time attribute, using classdiagram view and Custom Attributes dialog. For a boolean: DefaultValue(true) DefaultValue("true")...
1
3791
by: andy_from_fl | last post by:
I created a custom business object from the ground up- I applied the data binding interfaces, coded every property by hand, custom constructors, the whole deal. I wanted the columns to appear in a...
2
2278
by: filipk69 | last post by:
Could someone point me in the right direction, please. I have an enum something like this: enum TextFieldType { FieldABC = 3000, FieldXYZ = 3001, ….. ….. }
4
6803
by: =?Utf-8?B?QWJoaQ==?= | last post by:
I am using Reflection to invoke methods dynamically. I have got a special requirement where I need to pass a value to method by setting the custom method attribute. As I cannot change the...
0
7192
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7064
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7315
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4991
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4665
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
369
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.