reflection and web references

  • Thread starter Thread starter alexbf
  • Start date Start date
A

alexbf

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
 
alexbf said:
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.
 
alexbf said:
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.SoapHttpClientProtocol"?

If so, how?

Thanks,
Alex
 
alexbf said:
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.SoapHttpClientProtocol"?

Absolutely. Use Type.IsSubclassOf or Type.IsAssignableFrom. Of course,
there could be other subclasses there, but it's a reasonable
indication...
 
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.Services.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
 
alexbf said:
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.Services.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.
 
alexbf said:
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.Services.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 - <[email protected]>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.SoapHttpClientProtocol

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

If
GetType(System.Web.Services.Protocols.SoapHttpClientProtocol).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
 
Back
Top