473,218 Members | 1,726 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,218 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 1889
- 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Rodrigo Meneses | last post by:
Hello. Does somebody know how to invoke a web service using reflection in c#? Thanks in advance -Rodrigo Meneses Pinillos
0
by: david.kao | last post by:
Hi All: I am releasing a Win Client .Net program with Web Service in strong name though a shared network driver, and on each user’s desktop I am giving a machine level full trust with my win...
3
by: moflaherty | last post by:
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...
3
by: Steve Amey | last post by:
Hi all I am using reflection to read the values of properties from a class. The class is returned from a Web Service so I have to access the class using FieldInfo (Using VS 2003 which converts...
3
by: JT | last post by:
Hi, I am having trouble finding information about GUIDs and strong-names and don't really know what I need. If that's too ambiguous, please tell me where to look for info on these. Here's...
3
by: George | last post by:
Hello, I am building an assembly that connects to a third party application via http. I need create a http message that I post to the third party application. The message is very complicated...
1
by: John Bode | last post by:
I need a way to fake reflection in C++ code that makes as few assumptions about the data types involved as possible. I suspect there is no good answer for what I need to do, but I'll present the...
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...
6
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I am slightly familiar with reflection but have never done the following I know how to find a class and call but I haven't done the following The Method return a List of Another Class And...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.