473,397 Members | 2,099 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,397 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 1901
- 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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.