471,338 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Reflection in a Web Service?

This code works great in a windows application:

// Dynamically load the DLL
sDLLName = "..\\bin\\Test2.dll";
Assembly objAssembly = System.Reflection.Assembly.LoadFrom(sDLLName);

// Create an instance of the class
object testObject = objAssembly.CreateInstance("Test2.Test");

// Call the method "TestMessage" which has one argument
object[] object2 = new object[1];
object2[0] = 200;

MethodInfo Method = testObject.GetType().GetMethod("TestMessage");
object result = Method.Invoke(testObject, object2);

// This should return 300 and does
Console.WriteLine(result.ToString());

However, from a web service project, I can't seem to get this to work. It
can't find the DLL.

Questions:

* Does IIS sandbox the project and not allow external references?
* Is there a special way that IIS needs set up to allow this?
* I assume that IIS works with server paths, so maybe the path I have
specified above does not work. Should I be using a different path variable?
* Does IIS shadow the web service files to another location making this
approach impossible?

Any help is most appreciated!

Thanks!
Michael

Jul 21 '05 #1
3 1804
- asp.net doesn't sandbox by default (can change this in web.config)
- what happens if you change the code to?
sDLLName = "Test2.DLL";
Assembly.Load(sDLLName)

and place Test2.DLL in the bin directory of the web service

- asp.net does shadow copy DLLs but that shouldn't affect the path operations.

Niroo [MSFT]

"moflaherty" wrote:
This code works great in a windows application:

// Dynamically load the DLL
sDLLName = "..\\bin\\Test2.dll";
Assembly objAssembly = System.Reflection.Assembly.LoadFrom(sDLLName);

// Create an instance of the class
object testObject = objAssembly.CreateInstance("Test2.Test");

// Call the method "TestMessage" which has one argument
object[] object2 = new object[1];
object2[0] = 200;

MethodInfo Method = testObject.GetType().GetMethod("TestMessage");
object result = Method.Invoke(testObject, object2);

// This should return 300 and does
Console.WriteLine(result.ToString());

However, from a web service project, I can't seem to get this to work. It
can't find the DLL.

Questions:

* Does IIS sandbox the project and not allow external references?
* Is there a special way that IIS needs set up to allow this?
* I assume that IIS works with server paths, so maybe the path I have
specified above does not work. Should I be using a different path variable?
* Does IIS shadow the web service files to another location making this
approach impossible?

Any help is most appreciated!

Thanks!
Michael

Jul 21 '05 #2
Hi! The problem is that we use the same DLLs for other apps on the server.
For example, a windows service, desktop app, etc. It would be nice to have
the same DLL used in all cases and not 3 copies for each project.

Thanks!
Michael

"Niroo TP" wrote:
- asp.net doesn't sandbox by default (can change this in web.config)
- what happens if you change the code to?
sDLLName = "Test2.DLL";
Assembly.Load(sDLLName)

and place Test2.DLL in the bin directory of the web service

- asp.net does shadow copy DLLs but that shouldn't affect the path operations.

Niroo [MSFT]

"moflaherty" wrote:
This code works great in a windows application:

// Dynamically load the DLL
sDLLName = "..\\bin\\Test2.dll";
Assembly objAssembly = System.Reflection.Assembly.LoadFrom(sDLLName);

// Create an instance of the class
object testObject = objAssembly.CreateInstance("Test2.Test");

// Call the method "TestMessage" which has one argument
object[] object2 = new object[1];
object2[0] = 200;

MethodInfo Method = testObject.GetType().GetMethod("TestMessage");
object result = Method.Invoke(testObject, object2);

// This should return 300 and does
Console.WriteLine(result.ToString());

However, from a web service project, I can't seem to get this to work. It
can't find the DLL.

Questions:

* Does IIS sandbox the project and not allow external references?
* Is there a special way that IIS needs set up to allow this?
* I assume that IIS works with server paths, so maybe the path I have
specified above does not work. Should I be using a different path variable?
* Does IIS shadow the web service files to another location making this
approach impossible?

Any help is most appreciated!

Thanks!
Michael

Jul 21 '05 #3
As I mentioned before, you should always use Assembly.Load() instead of
Assembly.LoadFrom() when you are loading the assembly to use its
functionality.

If you want to have 1 copy of the files in a single location, you have a
few options:

1) Put the files in the Global Assembly Cache
http://msdn.microsoft.com/library/de...emblycache.asp

2) Use the codebase element of assemblyBinding in your config file:
http://msdn.microsoft.com/library/de...rfcodebase.asp

3) Use the probing element of assemblyBinding in your config file:
http://msdn.microsoft.com/library/de...grfprobing.asp
For a great resource on understanding Fusion (the .NET assembly loader),
do this workshop:
http://www.grimes.demon.co.uk/workshops/fusionWS.htm
Joshua Flanagan
http://flimflan.com/blog

moflaherty wrote:
Hi! The problem is that we use the same DLLs for other apps on the server.
For example, a windows service, desktop app, etc. It would be nice to have
the same DLL used in all cases and not 3 copies for each project.

Thanks!
Michael

"Niroo TP" wrote:

- asp.net doesn't sandbox by default (can change this in web.config)
- what happens if you change the code to?
sDLLName = "Test2.DLL";
Assembly.Load(sDLLName)

and place Test2.DLL in the bin directory of the web service

- asp.net does shadow copy DLLs but that shouldn't affect the path operations.

Niroo [MSFT]

"moflaherty" wrote:

This code works great in a windows application:

// Dynamically load the DLL
sDLLName = "..\\bin\\Test2.dll";
Assembly objAssembly = System.Reflection.Assembly.LoadFrom(sDLLName);

// Create an instance of the class
object testObject = objAssembly.CreateInstance("Test2.Test");

// Call the method "TestMessage" which has one argument
object[] object2 = new object[1];
object2[0] = 200;

MethodInfo Method = testObject.GetType().GetMethod("TestMessage");
object result = Method.Invoke(testObject, object2);

// This should return 300 and does
Console.WriteLine(result.ToString());

However, from a web service project, I can't seem to get this to work. It
can't find the DLL.

Questions:

* Does IIS sandbox the project and not allow external references?
* Is there a special way that IIS needs set up to allow this?
* I assume that IIS works with server paths, so maybe the path I have
specified above does not work. Should I be using a different path variable?
* Does IIS shadow the web service files to another location making this
approach impossible?

Any help is most appreciated!

Thanks!
Michael

Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Rodrigo Meneses | last post: by
reply views Thread by david.kao | last post: by
3 posts views Thread by moflaherty | last post: by
3 posts views Thread by George | last post: by
1 post views Thread by John Bode | last post: by
7 posts views Thread by =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post: by
6 posts views Thread by =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post: by
reply views Thread by rosydwin | last post: by

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.