473,326 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

reflection and web references

Hello,

I would like to know if it's possible using reflection to loop through
all "web references" of a given assembly and get the url as specified
in the web.config (dynamic url behavior).

Something like

for each objWebRef in [Assembly].GetWebReferences
Msgbox(objWebRef.url)
next

Thanks,
Alex

Aug 29 '07 #1
6 1739
alexbf <al****@gmail.comwrote:
I would like to know if it's possible using reflection to loop through
all "web references" of a given assembly and get the url as specified
in the web.config (dynamic url behavior).

Something like

for each objWebRef in [Assembly].GetWebReferences
Msgbox(objWebRef.url)
next
Web references don't really work like that - they're just autogenerated
proxy classes which are built into the "main" assembly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 29 '07 #2

On Aug 29, 3:59 pm, Jon Skeet [C# MVP] <sk...@pobox.comwrote:
alexbf <ale...@gmail.comwrote:
I would like to know if it's possible using reflection to loop through
all "web references" of a given assembly and get the url as specified
in the web.config (dynamic url behavior).
Something like
for each objWebRef in [Assembly].GetWebReferences
Msgbox(objWebRef.url)
next

Web references don't really work like that - they're just autogenerated
proxy classes which are built into the "main" assembly.

Yes I am aware of that... so basically, I am looking for a way to loop
through those "autogenerated proxy classes" to get the URL...

If I take the problem differently.. how can I distinguish between a
normal class and a "autogenerated proxy class"? Using reflection, can
I do a loop on classes that inherits from
"System.Web.Services.Protocols.SoapHttpClientProto col"?

If so, how?

Thanks,
Alex

Aug 29 '07 #3
alexbf <al****@gmail.comwrote:
Web references don't really work like that - they're just autogenerated
proxy classes which are built into the "main" assembly.

Yes I am aware of that... so basically, I am looking for a way to loop
through those "autogenerated proxy classes" to get the URL...

If I take the problem differently.. how can I distinguish between a
normal class and a "autogenerated proxy class"? Using reflection, can
I do a loop on classes that inherits from
"System.Web.Services.Protocols.SoapHttpClientProto col"?
Absolutely. Use Type.IsSubclassOf or Type.IsAssignableFrom. Of course,
there could be other subclasses there, but it's a reasonable
indication...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 29 '07 #4
On Aug 29, 4:44 pm, Jon Skeet [C# MVP] <sk...@pobox.comwrote:
alexbf <ale...@gmail.comwrote:
Web references don't really work like that - they're just autogenerated
proxy classes which are built into the "main" assembly.
Yes I am aware of that... so basically, I am looking for a way to loop
through those "autogenerated proxy classes" to get the URL...
If I take the problem differently.. how can I distinguish between a
normal class and a "autogenerated proxy class"? Using reflection, can
I do a loop on classes that inherits from
"System.Web.Services.Protocols.SoapHttpClientProto col"?

Absolutely. Use Type.IsSubclassOf or Type.IsAssignableFrom. Of course,
there could be other subclasses there, but it's a reasonable
indication...
If I try that :
Dim objClasse As Type
For Each objClasse In
[Assembly].GetExecutingAssembly.GetTypes()
Response.Write("// " & objClasse.Name & vbcrlf)
If
objClasse.IsAssignableFrom(GetType(System.Web.Serv ices.Protocols.SoapHttpClientProtocol))
Then
Response.Write("// WebService! " & objClasse.Name
& vbcrlf)
End If
Next

No proxy class shows up... as if they are not returned by "GetTypes()"

Is there another way to loop through classes?

Thanks,
Alex

Aug 29 '07 #5
alexbf <al****@gmail.comwrote:
If I try that :
Dim objClasse As Type
For Each objClasse In
[Assembly].GetExecutingAssembly.GetTypes()
Response.Write("// " & objClasse.Name & vbcrlf)
If
objClasse.IsAssignableFrom(GetType(System.Web.Serv ices.Protocols.SoapHttpClientProtocol))
Then
Response.Write("// WebService! " & objClasse.Name
& vbcrlf)
End If
Next

No proxy class shows up... as if they are not returned by "GetTypes()"

Is there another way to loop through classes?
IsAssignableFrom works the other way round. You should call it on the
SoapHttpClientProtocol type, passing in objClasse.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 29 '07 #6
On Aug 29, 5:33 pm, Jon Skeet [C# MVP] <sk...@pobox.comwrote:
alexbf <ale...@gmail.comwrote:
If I try that :
Dim objClasse As Type
For Each objClasse In
[Assembly].GetExecutingAssembly.GetTypes()
Response.Write("// " & objClasse.Name & vbcrlf)
If
objClasse.IsAssignableFrom(GetType(System.Web.Serv ices.Protocols.SoapHttpCl*ientProtocol))
Then
Response.Write("// WebService! " & objClasse.Name
& vbcrlf)
End If
Next
No proxy class shows up... as if they are not returned by "GetTypes()"
Is there another way to loop through classes?

IsAssignableFrom works the other way round. You should call it on the
SoapHttpClientProtocol type, passing in objClasse.

--
Jon Skeet - <sk...@pobox.com>http://www.pobox.com/~skeet Blog:http://www..msmvps.com/jon.skeet
If replying to the group, please do not mail me too- Hide quoted text -

- Show quoted text -
Thank you Jon, it works perfectly.

Here's my final code :

Dim objType As Type
Dim objWS As
System.Web.Services.Protocols.SoapHttpClientProtoc ol

For Each objType In
[Assembly].GetExecutingAssembly.GetTypes()

If
GetType(System.Web.Services.Protocols.SoapHttpClie ntProtocol).IsAssignableFrom(objType)
Then

'// The class is a webservice
objWS = Activator.CreateInstance(objType)

MsgBox("WebService : " & objType.Name & " - """ &
objWS.Url & """")
End If
Next
Best regards,
Alex
http://www.xicommunity.ca
http://www.myriadsuite.com

Aug 30 '07 #7

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

Similar topics

9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
7
by: John | last post by:
I have a class the reads in a file and sets the values of the file into its properties. This class is used to populate the data onto a form. This form has controls created at runtime based on...
4
by: Jimi | last post by:
Given a C# project file path, can I use reflection to get all the assemblies referenced by the project? e.g., I know the path of a C# project, say, "c:\SomeProject.csproj", and I want to load...
2
by: forvino | last post by:
Hi Geeks, Ihave a doubt in dotNet reflection. I m developing a tool which will returns set of public(access specifier) methods of the selected assembly. this works completely fine,...
6
by: ECathell | last post by:
I have a routine that compares 2 intances of the same object to see if there are any changes. The problem is that even though there are no changes, it tells me there are. I have even tried running a...
5
by: | last post by:
I am having problems with casting or converting a class to to an interface from which it derives. I'm certain that it's due to how it's being loaded, but I'm not sure how to get past the problem....
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
9
by: Michael Sander | last post by:
Hello ng, anyone knowns how to add a reference to an assembly to System.Reflection.AssemblyBuilder? In System.Web.Compilation.AssemblyBuilder is a function like AddAssemblyReference, but not in...
6
by: Cralis | last post by:
Hi guys, Someone once said, 'You can do that with reflection'. I can't recall what it was I was trying to do at the time, but then he said, 'Any developer knows what reflection is...'. I kept...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.