473,915 Members | 5,929 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reflection in a Web Service?

This code works great in a windows application:

// Dynamically load the DLL
sDLLName = "..\\bin\\Test2 .dll";
Assembly objAssembly = System.Reflecti on.Assembly.Loa dFrom(sDLLName) ;

// Create an instance of the class
object testObject = objAssembly.Cre ateInstance("Te st2.Test");

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

MethodInfo Method = testObject.GetT ype().GetMethod ("TestMessage") ;
object result = Method.Invoke(t estObject, object2);

// This should return 300 and does
Console.WriteLi ne(result.ToStr ing());

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 1930
- 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(s DLLName)

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.Reflecti on.Assembly.Loa dFrom(sDLLName) ;

// Create an instance of the class
object testObject = objAssembly.Cre ateInstance("Te st2.Test");

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

MethodInfo Method = testObject.GetT ype().GetMethod ("TestMessage") ;
object result = Method.Invoke(t estObject, object2);

// This should return 300 and does
Console.WriteLi ne(result.ToStr ing());

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(s DLLName)

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.Reflecti on.Assembly.Loa dFrom(sDLLName) ;

// Create an instance of the class
object testObject = objAssembly.Cre ateInstance("Te st2.Test");

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

MethodInfo Method = testObject.GetT ype().GetMethod ("TestMessage") ;
object result = Method.Invoke(t estObject, object2);

// This should return 300 and does
Console.WriteLi ne(result.ToStr ing());

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.LoadFr om() 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.Reflecti on.Assembly.Loa dFrom(sDLLName) ;

// Create an instance of the class
object testObject = objAssembly.Cre ateInstance("Te st2.Test");

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

MethodInfo Method = testObject.GetT ype().GetMethod ("TestMessage") ;
object result = Method.Invoke(t estObject, object2);

// This should return 300 and does
Console.Writ eLine(result.To String());

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
6771
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
984
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 program’s strong name key. Everybody seem working fine, except one user, his machine has no trouble to launch my app. But when my app starts talk to Web service, his machine gives him a permission error on Reflection. Here is the error message:...
3
348
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 instance of the class object testObject = objAssembly.CreateInstance("Test2.Test"); // Call the method "TestMessage" which has one argument
3
4114
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 the Properties into Fields when it comes out of the Web Service). I have this at the moment: Private _aDataSource As Object 'Person class
3
3797
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 what I am trying to accomplish: I need to know what assembly is calling methods in a web service. I also use ILMerge.exe to merge my assemblies into a single executable. One of the dlls in the executable calls the web service. I need to enforce...
3
319
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 with alot of business rules which I can define in a xml/config file. So, I will need to parse the xml file and also use reflection to retrieve certain data from my business objects via properties. This assembly will be used alot so performance is...
1
1725
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 case anyway. We have a class that normally registers with another service, which then executes callbacks in our class. Since that other service isn't going to be available for testing for a while, we're simulating it with a simple script-based...
7
2702
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 name based on the name of the VB6 application. A second choice would be a file name based on the # COM interface assembly. I have tried calling Assembly.GetCallingAssembly() but this fails when I use the VB6 client. Is there a way to get this...
6
1524
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 I need to pass in an Enumeration which is in the class that contains the method below 1)How do I create a List of this Class thru Reflection and once i populate it
0
10039
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11359
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10928
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11069
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9734
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7259
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4779
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.